创建一个继承自Pawn类的C++类 MyPawn 和 蓝图对象 BP_MyPawn
这里只介绍几个常用的,具体的可以参考官方文档
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();
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在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
UFUNCTION(BlueprintCallable, Category = "MyFunction", meta = (DisplayName = "PrintString"))
void MyPrintString(const FString &str);