Structs, USTRUCTS(), They're Awesome
Guide on using USTRUCTS by Rama the legend
Overview
Technical
Core Syntax
//If you want this to appear in BP, make sure to use this instead //USTRUCT(BlueprintType)
USTRUCT() struct FJoyStruct
{
GENERATED_BODY()
// Always make USTRUCT variables into UPROPERTY()
// any non-UPROPERTY() struct vars are not replicated
// So to simplify your life for later debugging, always use UPROPERTY()
UPROPERTY()
int32 SampleInt32;
//If you want the property to appear in BP, make sure to use this instead
//UPROPERTY(BlueprintReadOnly)
UPROPERTY()
AActor* TargetActor;
//Set
void SetInt(const int32 NewValue)
{
SampleInt32 = NewValue;
}
//Get
AActor* GetActor()
{
return TargetActor;
}
//Check
bool ActorIsValid() const
{
if(!TargetActor)
return false;
return TargetActor->IsValidLowLevel();
}
//Constructor
FJoyStruct()
{
// Always initialize your USTRUCT variables!
// exception is if you know the variable type has its own default
constructor SampleInt32 = 5;
TargetActor = nullptr;
}
};Examples
Example 1
Example 2
Structs With Struct Member Variables
Struct Assignment
Deep Copy
Automatic Make/Break in BP
Replication
Other notes
Related Links
Thank You Epic for USTRUCTS()
Authors
Last updated
Was this helpful?