This discussion is primarily focused on Unreal Engine C++
Structs are data structures that help you organize and manipulate related properties. For example, a Vector (FVector) is a commonly used Struct in Unreal defining an X, Y, and Z value.
In Unreal Engine, Structs may exist in either C++ or in Blueprint. Once created, you can use a Struct in a similar that you might use a fundamental data type (e.g. Integer, Bool, etc).
Declaring a USTRUCT in C++
Declaring a USTRUCT in C++ follows the same basic pattern as standard C++. Here is an example:
- Prepend the USTRUCT() macro above the declaration of your Struct's name
- Ensure that your Struct includes the GENERATED_BODY() macro. (In older code you may see GENERATED_USTRUCT_BODY() but this is no longer required nor necessary).
- That's it, you have created a USTRUCT. Be sure to mark any properties you want exposed to Unreal Engine's reflection system
A USTRUCT cannot be declared within the scope of another Class or Struct.
Exposing a USTRUCT declared in C++ to Blueprint
If you want Blueprint to be able to instantiate and manipulate your Blueprint, then ensure that:
- Your USTRUCT is declared as BlueprintType
- The UPROPERTY members of your Struct are declared as BlueprintRead or BlueprintReadWrite, as appropriate.
When a Struct is defined using the USTRUCT macro in C++, it becomes exposed to the Unreal Engine reflection system and may become
In the Unreal Engine, they're recognized by the Engine's reflection system, but are not part of the UObject ecosystem. As a result, they are faster to create than a UObject with the same data layout, and support UProperties, but will not be managed by the Garbage Collection system and cannot provide UFunctions. Keep in mind that UStructs cannot be used inside classes.
USTRUCT is a Macro used in UE4 C++ to specify certain settings and attributes.
When you declare a USTRUCT in Unreal Engine you can add a NetSerialize method which is part of the Unreal Engine struct trait system. If you define this method, the engine will use it while serializing and deserializing your struct for networking both during properties replication and RPC.
You can find a lot of documentation about serialization in this source file: Runtime/Engine/Classes/Engine/NetSerialization.h '''More information here!'''
Indicates that this struct should always be serialized as a single unit.
Exposes this struct as a type that can be used for variables in Blueprints.
Immutable is only legal in Object.h and is being phased out.
Do not use on new structs!
No autogenerated code will be created for this class; the header is only provided to parse metadata from.