Structs (or structures) are a composite data type that allow programmers to group members into a single type. A struct (in C++) can contain any combination of member variables including other struct types and member functions.
However this does not extend to Blueprint, structs created within the Unreal Editor are limited to member variables only as member functions cannot be declared with the UFUNCTION Macro.
USTRUCT(BlueprintType)
struct FYourStructName
{
GENERATED_BODY()
public:
UPROPERTY()
int32 YourMemberVariable;
};
All Structs in Unreal Engine 4 are prefixed with a capital F this is a form of Hungarian Notation Epic uses to identify certain types within their engine.
For a full list of prefixes used within the UE4 C++ code: ...
These macros are a way for Unreal Engine 4 to manage these as objects.
Without this declaration the struct is a standard C++ struct type. However when delcared as used with the parameter BlueprintType this becomes a managed object usable with UE4s Blueprint Editor.
For a member variable to be considered for replication it must use the UPROPERTY() macro.
Should not be used with Struct Member Functions!
There are a few different ways of defining default member variables for structs.
USTRUCT(BlueprintType)
struct FYourStructName
{
GENERATED_BODY()
public:
UPROPERTY()
int32 YourMemberVariable;
FYourStructName()
{
YourMemberVariable = 10;
}
};
USTRUCT(BlueprintType)
struct FLimitedResource
{
GENERATED_BODY()
UPROPERTY()
FName Name;
UPROPERTY()
FVector Value;
FLimitedResource()
: Name("Default"), Value(FVector(0.0f, 0.0f, 0.0f))
{}
FLimitedResource(const FName NewName, const FVector NewValue)
: Name(NewName), Value(NewValue)
{}
};
This is the most basic, using the default constructor to set the member variable once it is created.
When nesting structs it is important that the struct you wish to use as a member variable be delcared, you may want to seperate our your most use structs to a header which can be reused in many files.
USTRUCT(BlueprintType)
struct FYourFirstStructName
{
GENERATED_BODY()
public:
UPROPERTY()
int32 YourMemberVariable;
};
USTRUCT(BlueprintType)
struct FYourSecondStructName
{
GENERATED_BODY()
public:
UPROPERTY()
FYourFirstStructName YourStructMemberVariable;
};
USTRUCT(BlueprintType)
struct FYourFirstStructName
{
GENERATED_BODY()
public:
UPROPERTY()
int32 YourMemberVariable;
};
USTRUCT(BlueprintType)
struct FYourSecondStructName : public FYourFirstStructName
{
GENERATED_BODY()
};
Inherits YourMemberVariable from the parent Struct in the same way Class inheritance works.
Back to Main Page