【虚幻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;
相关推荐
鬼魅-95273 分钟前
VS+Qt中使用QCustomPlot绘制曲线标签(附源码)
c++·qt
Star在努力16 分钟前
15-C语言:第15~16天笔记
c语言·笔记·算法
xdlka1 小时前
C++初学者4——标准数据类型
开发语言·c++·算法
ZY小袁2 小时前
MGRE综合实验
服务器·网络·笔记·网络安全·学习方法·信息与通信·p2p
一位搞嵌入式的 genius2 小时前
暑期自学嵌入式——Day10(C语言阶段)
linux·笔记·学习·嵌入式c语言
被遗忘的旋律.2 小时前
Linux驱动开发笔记(五)——设备树(上)
linux·驱动开发·笔记
云边有个稻草人3 小时前
【C++】第十九节—一文万字详解 | AVL树实现
数据结构·c++·avl树·avl树的插入·avl树的旋转·avl树实现·avl树的结构
霜绛3 小时前
机器学习笔记(四)——聚类算法KNN、Kmeans、Dbscan
笔记·算法·机器学习·kmeans·聚类
略无慕艳意8 小时前
【笔记】Visual Studio 2022 入门指南
c++·c·cmake·microsoft visual studio 2022
飞速移动的代码菌10 小时前
【DataWhale】快乐学习大模型 | 202507,Task08笔记
笔记·学习