Using Structs

Get started using Structs with this short guide

Choose your operating system:

Windows

macOS

Linux

Structs (or UStructs ) are data structures that help you organize and manipulate related properties. By using structs, you can create custom variable types to help organize your project. This guide will help you set up structs, and give some insight into how they can be customized.

Implementing Structs

  1. Open the header (.h) file where you want to define your struct.

  2. Define your C++ struct and add the USTRUCT macro before it, including any UStruct Specifiers your struct needs.

  3. Add the GENERATED_BODY macro to the top of your struct.

  4. You can now tag the struct's member variables with UPROPERTY to make them visible to UE's reflection system and Blueprint Scripting.

    1. Check out this list of UProperty Specifiers to see how the property can behave within various aspects of the Engine and Editor.

Example

USTRUCT(BlueprintType)
struct FMyStruct
{
    GENERATED_BODY()

    //~ The following member variable will be accessible by Blueprint Graphs:
    // This is the tooltip for our test variable.
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Test Variables")
    int32 MyIntegerMemberVariable;

    //~ The following member variable will be not accessible by Blueprint Graphs:
    int32 NativeOnlyMemberVariable;

    /**~
    * This UObject pointer is not accessible to Blueprint Graphs, but
    * is visible to UE4's reflection, smart pointer, and garbage collection
    * systems.
    */
    UPROPERTY()
    UObject* SafeObjectPointer;
};

Additional Information

Here are some helpful hints and things to remember when using Structs:

  1. UStructs can use UE's smart pointer and garbage collection systems to prevent UObjects from being removed by garbage collection.

  2. Structs are different from UObjects, and because of this Structs are best used for simple data types.

    1. For more complicated interactions within your project, you may want to make a UObject or AActor subclass instead.

  3. UStructs ARE NOT considered for replication.

    1. UProperty variables ARE considered for replication.

  4. UE has the ability to automatically create Make and Break functions for Structs.

    1. Make appears for any UStruct with the BlueprintType tag.

    2. Break appears if you have at least one BlueprintReadOnly or BlueprintReadWrite property in the UStruct.

    3. The pure node that Break creates will provide one output pin for each property tagged as BlueprintReadOnly or BlueprintReadWrite .

언리얼 엔진 문서의 미래를 함께 만들어주세요! 더 나은 서비스를 제공할 수 있도록 문서 사용에 대한 피드백을 주세요.
설문조사에 참여해 주세요
건너뛰기