keywords: UE4 stylized Enum and Struct in C++

enum

1, define

UENUM()
enum EEnemyStatus
{
    ES_Stopped     UMETA(DisplayName = "Stopped"),
    ES_Moving      UMETA(DisplayName = "Moving"),
    ES_Attacking   UMETA(DisplayName = "Attacking"),
};

2, using

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Status)
TEnumAsByte<EEnemyStatus> Status;
struct

1, define

USTRUCT(BlueprintType)
struct TESTPROJ_API FMyStruct
{
    GENERATED_USTRUCT_BODY()

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Test")
        int32 Test;

    FMyStruct() { }
};

2, using

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
FMyStruct Test;
Issues

Example:

UPROPERTY(BlueprintReadWrite)
TArray<FMyStruct*> AnimArray;

Error at building:

error : Inappropriate '*' on variable of type 'FMyStruct', cannot have an exposed pointer to this type.

Caused by:
The Unreal property system that Blueprints are built on top only support passing pointers to non-UObjects, you can only pass them ‘by value’ or ‘by reference’.

Solution:
Using reference instead of pointer.

UPROPERTY(BlueprintReadWrite)
TArray<FMyStruct&> AnimArray;

Or by value:

UPROPERTY(BlueprintReadWrite)
TArray<FMyStruct> AnimArray;

Reference:
https://answers.unrealengine.com/questions/132416/how-do-i-expose-a-pointer-to-a-struct.html


我们拥有艺术,所以不会被真相击垮。 -尼采