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
- Open the header (.h) file where you want to define your struct.
- Define your C++ struct and add the
USTRUCTmacro before it, including any UStruct Specifiers your struct needs. - Add the
GENERATED_BODYmacro to the top of your struct. - You can now tag the struct’s member variables with
UPROPERTYto make them visible to UE’s reflection system and Blueprint Scripting.- 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:
UStructscan use UE's smart pointer and garbage collection systems to preventUObjectsfrom being removed by garbage collection.- Structs are different from
UObjects,and because of this Structs are best used for simple data types.- For more complicated interactions within your project, you may want to make a
UObjectorAActorsubclass instead.
- For more complicated interactions within your project, you may want to make a
UStructsARE NOT considered for replication.UPropertyvariables ARE considered for replication.
- UE has the ability to automatically create Make and Break functions for Structs.
- Make appears for any
UStructwith theBlueprintTypetag. - Break appears if you have at least one
BlueprintReadOnlyorBlueprintReadWriteproperty in the UStruct. - The pure node that Break creates will provide one output pin for each property tagged as
BlueprintReadOnlyorBlueprintReadWrite.
- Make appears for any