【虚幻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;
相关推荐
明月看潮生2 分钟前
青少年编程与数学 02-010 C++程序设计基础 44课题、QT
开发语言·c++·qt·青少年编程·编程与数学
酷酷的崽79825 分钟前
如何在AVL树中高效插入并保持平衡:一步步掌握旋转与平衡因子 —— 旋转篇
c语言·数据结构·c++·算法
宇寒风暖30 分钟前
一文弄懂编辑距离算法(Levenshtein Distance)示例,通过动态规划计算两个字符串之间的最小编辑操作次数(插入、删除、替换)
开发语言·数据结构·笔记·学习·算法·动态规划
EPSDA34 分钟前
介绍HTTP协议基本结构与Linux中基本实现HTTPServer
linux·运维·开发语言·c++·网络协议·tcp/ip·http
小温不会码1 小时前
深入理解C/C++堆数据结构:从原理到实战
数据结构·c++·算法
尽力不摆烂的阿方1 小时前
《图解设计模式》 学习笔记
java·笔记·学习·设计模式
0^11 小时前
Flutter笔记
笔记·flutter
乘风上菜2 小时前
C++类与对象——拷贝构造与运算符重载
开发语言·c++
努力努力再努力wz2 小时前
【Linux内核系列】:文件系统收尾以及软硬链接详解
linux·运维·服务器·c++·c
Source.Liu2 小时前
【CXX】6.7 SharedPtr<T> — std::shared_ptr<T>
c++·rust·cxx