【虚幻C++笔记】枚举UENUM、结构体USTRUCT

目录

枚举(UENUM)

第一种:使用命名空间

C++ 复制代码
UENUM(BlueprintType)
namespace MyEnumType
{
    enum MyCustomEnum
    {
       Type1,// 或者使用带 DisplayName别名 ==> Enum1 UMETA(DisplayName = "Type1"),
       Type2,
       Type3,
    }
}
C++ 复制代码
//在蓝图中声明
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyEnumType")
TEnumAsByte<MyEnumType::MyCustomType> MyEnumType;

第二种:继承uint8通过申明class类别名来替代

C++ 复制代码
UENUM(BlueprintType)
enum class MyEnumType2 : uint8
{
  Enum1 UMETA(DisplayName = "Type1"),
  Enum2 UMETA(DisplayName = "Type2"),
  Enum3 UMETA(DisplayName = "Type3"),
  Enum4 UMETA(DisplayName = "Type4"),
};
C++ 复制代码
//在蓝图中声明
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyEnumType2")
TEnumAsByte<MyEnumType2> MyEnumType2;

结构体(USTRUCT)

复制代码
// 暴露给蓝图
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="MyStructType")
int32 Age;
// 不暴露给蓝图
int32 Age;
// 蓝图图表无法访问此UObject指针,但是指针对UE的反射、智能指针和垃圾回收系统可见。
UPROPERTY()
UObject* ObjectPointer;
C++ 复制代码
//注意,定义结构体名称前要加F前缀,不然编译不通过。
USTRUCT(BlueprintType)
struct FMyCustomStruct
{
  GENERATED_USTRUCT_BODY()

  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  FString ID;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  FString Name;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  int32 Age;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  float Height;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  bool IsMan;
};
C++ 复制代码
//结构体创建数据表格,需继承FTableRowBase
USTRUCT(BlueprintType)
struct FMyCustomStruct:public FTableRowBase
{
  GENERATED_USTRUCT_BODY()

  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  FString ID;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  FString Name;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  int32 Age;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  float Height;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  bool IsMan;
};
C++ 复制代码
//在蓝图中声明
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyExposeOnSpawn", meta = (ExposeOnSpawn = "ExposeOnSpawnValue"))
FMyCustomStruct MyCustomStruct;
相关推荐
love530love7 小时前
【笔记】在 MSYS2(MINGW64)中正确安装 Rust
运维·开发语言·人工智能·windows·笔记·python·rust
南郁8 小时前
007-nlohmann/json 项目应用-C++开源库108杰
c++·开源·json·nlohmann·现代c++·d2school·108杰
xhyu618 小时前
【学习笔记】On the Biology of a Large Language Model
笔记·学习·语言模型
小白杨树树8 小时前
【SSM】SpringMVC学习笔记7:前后端数据传输协议和异常处理
笔记·学习
菠萝019 小时前
共识算法Raft系列(1)——什么是Raft?
c++·后端·算法·区块链·共识算法
海棠蚀omo9 小时前
C++笔记-C++11(一)
开发语言·c++·笔记
阑梦清川10 小时前
HZOJ新手村前段时间的刷题的笔记
笔记
FakeOccupational10 小时前
【p2p、分布式,区块链笔记 MESH】Bluetooth蓝牙通信拓扑与操作 BR/EDR(经典蓝牙)和 BLE
笔记·分布式·p2p
凌佚10 小时前
rknn优化教程(一)
c++·目标检测·性能优化