Using Structs

Get started using Structs with this short guide

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.

Select Skin
Light
Dark

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback