UE5 C++(五)— UPROPERTY宏(属性说明符和元数据说明符)
前提
创建一个继承自Pawn类的C++类 MyPawn 和 蓝图对象 BP_MyPawn
属性说明符
这里只介绍几个常用的,具体的可以参考官方文档
-
UPROPERTY(VisibleDefaultsOnly): 仅在默认设置下可见
-
UPROPERTY(VisibleInstanceOnly):仅在实例化细节面板可见
-
UPROPERTY(VisibleAnywhere):类默认设置和实例化细节面板都可见
-
UPROPERTY(EditDefaultsOnly):仅在默认设置下可编辑
-
UPROPERTY(EditInstanceOnly):仅在实例化细节面板可编辑
-
UPROPERTY(EditAnywhere) :类默认设置和实例化细节面板都可编辑
-
UPROPERTY(EditAnywhere,BlueprintReadOnly):仅在蓝图中可读
-
UPROPERTY(EditAnywhere,BlueprintReadWrite):在蓝图中可读、可写 可以获取和设置变量
-
Category目录
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category =“MyIntValue”)
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “MyIntValue|MySubIntValue”)
元数据说明符
这里只介绍几个常用的,具体的可以参考官方文档
-
DisplayName别名
UPROPERTY(EditAnywhere,BlueprintReadWrite, meta=(DisplayName=“MyValue3DisplayName”))
-
条件控制编辑:
UPROPERTY(EditAnywhere, BlueprintReadWrite,meta = (DisplayName = “Controller”))
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (EditCondition = “isController”))
float ControllerValueInt32;
-
ToolTip提示 解释说明变量
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = “isControllerTrue”))
bool isControllerTrue;
函数在蓝图中使用
// 函数在蓝图中调用
UFUNCTION(BlueprintCallable, Category = "MyFunction")
void MyFunction1();
// 纯虚函数在蓝图中调用 BlueprintPure
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "MyFunction")
bool MyFunction2();
BlueprintImplementableEvent
BuleprintImplementableEvent在C++中声明,不能定义,蓝图可重载
声明带有BuleprintImplementableEvent函数在.h文件中声明,不需要在.cpp文件中实现
不带返回值:
// BuleprintImplementableEvent在C++中声明,不能定义,蓝图可重载
UFUNCTION(BlueprintImplementableEvent, Category = "BIEFunction")
void MyFunction3();
UFUNCTION(BlueprintImplementableEvent, Category = "BIEFunction")
void MyFunction5(const FString &str);
带返回值:
// BuleprintImplementableEvent在C++中声明,不能定义,蓝图可重载
UFUNCTION(BlueprintImplementableEvent, Category = "BIEFunction")
bool MyFunction4();
UFUNCTION(BlueprintImplementableEvent, Category = "BIEFunction")
bool MyFunction7(const FString &str);
BlueprintNativeEvent
BlueprintNativeEvent在C++中声明,可以定义,蓝图可重载、不可重载都可以。
声明带有BuleprintImplementableEvent函数在.h文件中声明,需要在.cpp文件中实现。实现时在函数末尾添加_Implementation
不带返回值:
// BlueprintNativeEvent在C++中声明,可以定义,蓝图可重载或不可重载
UFUNCTION(BlueprintNativeEvent, Category = "BNEFunction")
void MyFunction8();
UFUNCTION(BlueprintNativeEvent, Category = "BNEFunction")
void MyFunction10(const FString &str);
void AMyPawn::MyFunction8_Implementation()
{
}
void AMyPawn::MyFunction10_Implementation(const FString &str)
{
}
带返回值:
// BlueprintNativeEvent在C++中声明,可以定义,蓝图可重载或不可重载
UFUNCTION(BlueprintNativeEvent, Category = "BNEFunction")
bool MyFunction9();
UFUNCTION(BlueprintNativeEvent, Category = "BNEFunction")
bool MyFunction11(const FString &str);
bool AMyPawn::MyFunction9_Implementation()
{
return true;
}
bool AMyPawn::MyFunction11_Implementation(const FString &str)
{
return true;
}
元数据说明符meta 别名作用
//元数据说明符meta
UFUNCTION(BlueprintCallable, Category = "MyFunction", meta = (DisplayName = "PrintString"))
void MyPrintString(const FString &str);
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!