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
USTRUCT
macro before it, including any UStruct Specifiers your struct needs. - Add the
GENERATED_BODY
macro to the top of your struct. - You can now tag the struct’s member variables with
UPROPERTY
to 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:
UStructs
can use UE's smart pointer and garbage collection systems to preventUObjects
from 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
UObject
orAActor
subclass instead.
- For more complicated interactions within your project, you may want to make a
UStructs
ARE NOT considered for replication.UProperty
variables ARE considered for replication.
- UE has the ability to automatically create Make and Break functions for Structs.
- Make appears for any
UStruct
with theBlueprintType
tag. - Break appears if you have at least one
BlueprintReadOnly
orBlueprintReadWrite
property in the UStruct. - The pure node that Break creates will provide one output pin for each property tagged as
BlueprintReadOnly
orBlueprintReadWrite
.
- Make appears for any