【虚幻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;
相关推荐
钟离墨笺6 分钟前
【c++】【智能指针】什么情况下不适合智能指针
开发语言·c++
jingjingjing11111 小时前
笔记:代码随想录算法训练营day48:739. 每日温度\496.下一个更大元素 I\503.下一个更大元素II
笔记
郭源潮11 小时前
《C++知识梳理及常见面试题》
c++
勇敢滴勇2 小时前
【C++】二叉搜索树(二叉查找树、二叉排序树)详解
开发语言·c++·算法·霍夫曼树
f狐0狸x2 小时前
【蓝桥杯每日一题】3.16
c++·算法·蓝桥杯
webrtc&ffmpeg_study2 小时前
操作系统八股文整理(一)
c++·操作系统
UestcXiye2 小时前
《TCP/IP网络编程》学习笔记 | Chapter 18:多线程服务器端的实现
c++·计算机网络
Zfox_2 小时前
【Linux】五种 IO 模型与非阻塞 IO
linux·运维·服务器·c++·io模型
周Echo周2 小时前
8、STL中的map和pair使用方法
开发语言·数据结构·c++·考研·算法·leetcode·pat考试
Zhouqi_Hua2 小时前
LLM论文笔记 24: A Theory for Length Generalization in Learning to Reason
论文阅读·人工智能·笔记·深度学习·语言模型·自然语言处理