【UE4学习】13_UFUNCTION 关键字解释

来源:互联网 发布:淘宝店铺logo免费设计 编辑:程序博客网 时间:2024/05/16 23:52

在本文中,将会陆续使用程序实例来解释关键字


(1)关键字 part 1

BlueprintCallable
BlueprintImplementableEvent
Category


BlueprintCallable 进一步用法


.h

UENUM(BlueprintType)enum class EMyEnum : uint8{BranchA,BranchB};
        ///Category = "MyActor|Sub1" 中 "|" 为分类下的子类///Meta = (ExpandEnumAsExecs = "Branches") 代表作为执行节点输出UFUNCTION(BlueprintCallable, Category = "MyActor|Sub1", Meta = (ExpandEnumAsExecs = "Branches"))void FunTest4(int32 Input, EMyEnum& Branches);
<span style="font-size:14px;">.cpp</span>
void AMyActor::FunTest4(int32 Input, EMyEnum& Branches){if (Input==1){Branches = EMyEnum::BranchA;}else{Branches = EMyEnum::BranchB;}}


(2)关键字 part 2

BlueprintNativeEvent

该关键字,表示函数可被蓝图重载,也可被C++正常实现。当C++有实现,蓝图也有重载的时候,C++的代码被覆盖。如果此时既想要使用蓝图重载后的方法,也想使用C++实现的方法,可以在C++ 中提取函数名_Implementation() 到新的函数,以供调用。(存疑)


.h

///BlueprintNativeEvent 可在蓝图中重载,也可在C++中正常实现方法的具体内容///DisplayName 蓝图中实际调用的函数名///DeprecationMessage显示警告信息UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "MyActor",Meta=(DisplayName="FunTest5_DisplayName(...)", DeprecatedFunction, DeprecationMessage = "This FunTest5."))void FunTest5(const TArray<FString>& input, TArray<FString>& output);

.cpp

void AMyActor::FunTest5_Implementation(const TArray<FString>& input, TArray<FString>& output){}


在这里,可以看一下输入参数和输出参数的设置,带const 和不带const的区别。

(2)关键字 part3

Exec

此函数可从游戏中的控制台中执行。Exec命令仅在特定类中声明时才产生作用。包括:

Pawns,

Player Controllers,

Player Input,

Cheat Managers,

Game Modes,

Game Instances,

overriden Game Engine classes,

Huds


             具体参考:点击打开链接

MyPawn.h

        UFUNCTION(Exec)void SetValue(float Value);</span>

MyPawn.cpp

void AMyPawn::SetValue(float Value){}




参考 :

  1、UE4 UFUNCTION Keywords Explained

2、Function definitions (Official Docs)

3、Extending Blueprints

4、UF::

5、分享C++寫blueprint block的方法

0 0
原创粉丝点击