UENUM枚举宏、USTRUCT结构体宏


//.h声明枚举和结构体
#include "CoreMinimal.h
#include "GameFramework/Pawn.h"
#include "MyPawn.generated.h"
UENUM(BlueprintType)
namespace MyEnumType
{
enum MyCustomEnum
{
Type1,
Type2,
Type3,
}
}

其中的BlueprintType可以让蓝图可以创建和选择该变量

2024-04-06-18-49-42.png


//结构体必须以F开头
USTRUCT(BlueprintType)
struct FMyTestStruct
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyTestStruct")
int32 Health;
UPROPERTY(EditAnywhere,BlueprintReadWrite, Category ="MyTestStruct")
FString MyName;
}

2024-04-06-18-52-41.png


//使用TEnumAsByte模板声明枚举变量
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category ="MyEnum")
TEnumAsByte<MyEnumType::MyCustomEnum> MyCustomEnum1;

//结构体不需要使用模板,正常声明即可
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category ="MyCustomStruct")
FMyTestStruct MyCustomStruct;

2024-04-06-18-53-34.png