UE4入门-常见的宏-UFUNCTION

原文链接: https://blog.csdn.net/u012793104/article/details/78487893

基本功能:定义能够被UE识别的函数


本文只对部分常用的修饰属性做用法说明,高端的后面接触到了再补充,大佬勿喷

Unreal Engine version == 4.18.0 ; Virtual Studio 2017 update 15.4.2


函数说明符

  • BlueprintAuthorityOnly
    如果在具有网络权限的计算机(服务器,专用服务器或单人游戏)上运行,此功能只能从Blueprint代码执行,如无网络权限,则该函数将不会从蓝图代码中执行

  • BlueprintCallable
    该函数可以在蓝图或关卡蓝图图表中执行

    public: 
        UFUNCTION(BlueprintCallable, Category = "Snowing,BlueprintFunc")
            void BlueprintCallableFunction();
    • 1
    • 2
    • 3

    这里写图片描述

  • BlueprintCosmetic
    此函数为修饰函数而且无法运行在专属服务器上

  • BlueprintGetter 修饰自定义的Getter函数专用【例子见UE4入门-常见的宏-UPROPERTY
    该函数将用作Blueprint暴露属性的访问器。这个说明符意味着BlueprintPure和BlueprintCallable

  • BlueprintSetter 修饰自定义的Setter函数专用【例子见UE4入门-常见的宏-UPROPERTY
    此函数将用作Blueprint暴露属性的增变器。这个说明符意味着BlueprintCallable

  • BlueprintImplementableEvent
    此函数可以在蓝图或关卡蓝图图表内进行重载
    不能修饰private级别的函数,函数在C++代码中不需要实现定义

    public:
        UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Blueprint Implementable Event Function"), Category = "Snowing|BlueprintFunc")
            float BlueprintImplementableEventFunction(float In_Float);
    • 1
    • 2
    • 3

    这里写图片描述
    这里写图片描述

  • BlueprintInternalUseOnly
    表示该函数不应该暴露给最终用户

  • BlueprintNativeEvent
    此函数将由蓝图进行重载,但同时也包含native类的执行。提供一个名称为[FunctionName]_Implementation的函数本体而非[FunctionName];自动生成的代码将包含转换程序,此程序在需要时会调用实施方式

    // .h文件中的声明
    public:
        UFUNCTION(BlueprintNativeEvent, meta = (DisplayName = "Blueprint Native Event Function"), Category = "Snowing|BlueprintFunc")
            FString BlueprintNativeEventFunction(AActor* In_AActor);
    
    // .cpp中的定义
    FString AActorTest::BlueprintNativeEventFunction_Implementation(AActor* In_AActor)
    {
        return In_AActor->GetName();
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    这里写图片描述
    这里写图片描述

  • BlueprintPure
    该函数不会以任何方式影响拥有对象,并且可以在蓝图或级别蓝图图表中执行

    // .h文件中的声明
    public:
        UFUNCTION(BlueprintPure, Category = "Snowing|BlueprintFunc")
            AActor* BlueprintPureFunction();
    
    // .cpp中的定义
    AActor* AActorTest::BlueprintPureFunction()
    {
        return this;
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    这里写图片描述

  • CallInEditor
    该函数可以在编辑器中通过详细信息面板中的按钮在选定实例中调用

  • Category = TopCategory|SubCategory|Etc
    指定函数在编辑器中的显示分类层级,| 是分层级的符号

    UFUNCTION(BlueprintPure, Category = "Snowing|BlueprintFunc")
        AActor* BlueprintPureFunction();
    • 1
    • 2

    这里写图片描述

  • Client
    此函数仅在该函数从属对象所从属的客户端上执行。提供一个名称为[FunctionName]_Implementation的函数主体,而不是[FunctionName]; 自动生成的代码将包含一个转换程序来在需要时调用实现方法

  • CustomThunk
    UnrealHeaderTool(虚幻头文件工具)的代码生成器将不会为此函数生成execFoo转换程序; 可由用户来提供

  • Exec
    此函数可从游戏中的控制台中执行。Exec命令仅在特定类中声明时才产生作用
    此标记修饰的函数应在可以接受输入的类中,才能正常接受命令

    //CharacterTest.h
    UCLASS()
    class UNREALCPPLEARN_API ACharacterTest : public ACharacter
    {
    GENERATED_BODY()
    
    public:
    // Sets default values for this character's properties
    ACharacterTest();
    
    protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
    
    public: 
    // Called every frame
    virtual void Tick(float DeltaTime) override;
    
    // Called to bind functionality to input
    virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
    
    UFUNCTION(Exec)
        void ExecFunction();
    
    UPROPERTY()
        bool IsShow;
    };
    
    //CharacterTest.cpp
    void ACharacterTest::Tick(float DeltaTime)
    {
        Super::Tick(DeltaTime);
        if (IsShow)
        {
            FString  TempText = "What is this, WTF";
            if (GEngine)
            {
                GEngine->AddOnScreenDebugMessage(-1, 8.f, FColor::Red, TempText);
            }
            UE_LOG(LogTemp, Log, TEXT("This is ExecFunction------"));
        }
    }
    
    void ACharacterTest::ExecFunction()
    {
        IsShow = !IsShow;
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    这里写图片描述这里写图片描述

  • NetMilticast
    无论角色的NetOwner如何,该函数都在服务器上本地执行并复制到所有客户端

  • Reliable / UnReliable
    Reliable函数在网络间进行复制,并会忽略带宽或网络错误而被确保送达。仅在与客户端或服务器共同使用时可用
    UnReliable函数在网络间复制,但可能会由于带宽限制或网络错误而传送失败。仅在与客户端或服务器一起使用时有效

  • SealeEvent
    这个函数不能在子类中重写。 SealedEvent关键字只能用于事件。对于非事件函数,声明它们是static的还是final的来封闭它们

  • ServiceRequest / ServiceResponse
    ServiceRequest函数是一个RPC服务请求
    ServiceResponse函数是一个RPC服务响应

  • Server
    此函数仅在服务器上执行。提供一个名称为[FunctionName]_Implementation的函数主体,而不是[FunctionName]; 自动生成的代码将包含一个转换程序来在需要时调用实现方法

  • WithValidation
    声明一个名为与main函数相同的附加函数,但将_Validation添加到最后。该函数采用相同的参数,并返回一个布尔值来指示是否应该继续调用主函数


元数据说明符

用法:UFUNCTION( [函数说明符], meta = (元数据说明符) )

  • AdvancedDisplay=”Parameter1, Parameter2, …”
    逗号分隔的参数列表将显示为高级引脚(需要UI扩展)

    UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "In_FString"), Category = "Snowing|BlueprintFunc")
        void BlueprintCallableFunction(TArray<FString> In_TArray, UPARAM(Ref)FString& In_FString, float& Out_Float);
    • 1
    • 2

    这里写图片描述

  • AdvancedDisplay=N
    将N替换为数字,N之后的所有参数都将显示为高级引脚(需要UI扩展)。例如。 ‘AdvancedDisplay = 2’会将前两个参数,其他的参数都标记为高级)

  • ArrayParm=”Parameter1, Parameter2, …”
    表示BlueprintCallable函数应使用“调用数组函数”节点,并将列出的参数视为通配符数组属性

    UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "In_FString", ArrayParm = "In_TArray"), Category = "Snowing|BlueprintFunc")
        void BlueprintCallableFunction(TArray<FString> In_TArray, UPARAM(Ref)FString& In_FString, float& Out_Float);
    • 1
    • 2

    这里写图片描述

  • ArrayTypeDependentParams=”Parameter”
    使用ArrayParm时,此说明符指示一个参数,该参数将确定ArrayParm列表中的所有参数的类型

    UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "In_FString", ArrayParm = "In_TArrayFStting, In_TArrayInt", ArrayTypeDependentParams = "In_TArrayInt"), Category = "Snowing|BlueprintFunc")
        void BlueprintCallableFunction(TArray<FString> In_TArrayFString, TArray<int32> In_TArrayInt, UPARAM(Ref)FString& In_FString, float& Out_Float);
    • 1
    • 2

    这里写图片描述

  • AutoCreateRefTerm=”Parameter1, Parameter2, …”
    列出的参数虽然通过引用传递,但如果它们的引脚保持断开连接,则会有自动创建的默认参数。这是蓝图的便利功能

    //.h文件函数声明
    UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "In_Int32"), Category = "Snowing|Editor")
        uint8 AutoCreateRefTermFunction(UPARAM(Ref) int32& In_Int32);
    
    //.cpp文件函数定义
    uint32 AActorTest::AutoCreateRefTermFunction(UPARAM(Ref) int32& In_Int32)
    {
        return fabs(In_Int32);
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    这里写图片描述

  • BlueprintAutocast
    仅由Blueprint函数库中的静态BlueprintPure函数使用。 Cast节点将自动添加返回类型和函数的第一个参数的类型

  • BlueprintInternalUseOnly
    这个函数是一个内部的实现细节,用来实现另一个函数或节点。它不会直接暴露在蓝图图表中

  • BlueprintProtected
    该功能只能在蓝图中拥有的对象上调用。它不能在另一个实例上调用

  • CallableWithoutWorldContext
    用于具有WorldContext引脚的BlueprintCallable函数,以指示即使函数的类未实现GetWorld函数也可以调用该函数

  • CommutativeAssociativeBinaryOperator=”true”
    指示BlueprintCallable函数应该使用“Commutative Associative Binary”节点。该节点缺少引脚名称,但具有创建附加输入引脚的“Add Pin”按钮

    //.h文件函数声明
    UFUNCTION(BlueprintPure, meta = (DisplayName = "Add Pin Function", CommutativeAssociativeBinaryOperator = "true"), Category = "Snowing|Parameters")
        float CommutativeAssociativeBinaryOperatorFunction(const float A, const float B);
    
    //.cpp文件行数定义
    float AActorTest::CommutativeAssociativeBinaryOperatorFunction(const float A, const float B)
    {
        float Result{0.f};
        Result += A;
        Result += B;
    
        return Result;
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    这里写图片描述

  • CompactNodeTitle=”Name”
    指示BlueprintCallable函数应在紧凑显示模式下显示,并提供在该模式下显示的名称

    UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "In_Int32", CompactNodeTitle = "CompactNodeTitleFunction"), Category = "Snowing|Parameters")
        int32 AutoCreateRefTermFunction(UPARAM(Ref) int32& In_Int32);
    • 1
    • 2

    这里写图片描述

  • CustomStructureParam=”Parameter1, Parameter2, …”
    列出的参数都被视为通配符。此说明符要求 UFUNCTION 级别说明符 CustomThunk, 这将要求用户提供自定义 exec 函数。在此函数中, 可以检查参数类型, 并根据这些参数类型进行相应的函数调用。不应调用基 UFUNCTION, 如果是, 则应断言或记录错误

  • DefaultToSelf
    对于BlueprintCallable函数,这表示Object属性的默认值应该是节点的自身上下文

  • DeprecatedFunction
    任何对此函数的蓝图引用都会导致编译警告, 告诉用户该函数已被弃用。可以使用 DeprecationMessage 元数据说明符来添加到弃警告消息 (例如, 提供有关替换已弃用的函数的说明)
    添加这个标记后,在4.18.0引擎中(可能以及后续版本),蓝图无法查找到被标记的函数

    UFUNCTION(BlueprintCallable, meta = (DeprecatedFunction, DeprecationMessage = "This is Deprecation Message"), Category = "Snowing|BlueprintFunc")
        void DeprecatedFunctionFunction();
    • 1
    • 2

    这里写图片描述

  • DeprecationMessage=”MessageText”
    如果该函数已被弃用,则在尝试编译使用该函数的Blueprint时,此消息将被添加到标准弃用警告中

  • DisplayName=”Blueprint Node Name”
    蓝图中此节点的名称将替换为此处提供的值,而不是代码生成的名称(在蓝图中搜索被修饰函数也用这里提供的值)

    //.h文件函数声明
    UFUNCTION(BlueprintPure, meta = (DisplayName = "Add Pin Function", CommutativeAssociativeBinaryOperator = "true"), Category = "Snowing|Parameters")
        float CommutativeAssociativeBinaryOperatorFunction(const float A, const float B);
    
    //.cpp文件行数定义
    float AActorTest::CommutativeAssociativeBinaryOperatorFunction(const float A, const float B)
    {
        float Result{0.f};
        Result += A;
        Result += B;
    
        return Result;
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    这里写图片描述

  • ExpandEnumAsExecs=”Parameter”
    对于BlueprintCallable函数,这表示应该为参数使用的枚举中的每个条目创建一个输入执行引脚。指定的参数必须是由引擎通过UENUM标签识别的枚举类型

    UENUM()
    enum _EnumParam
    {
    E_1 = 0,
    E_2,
    E_3
    };
    
    UFUNCTION(BlueprintCallable, meta = (ExpandEnumAsExecs = "In_EnumParam"), Category = "Snowing|Parameters")
        void ExpandEnumAsExecsFunction(_EnumParam In_EnumParam);
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    这里写图片描述

  • HidePin=”Parameter”
    对于BlueprintCallable函数,这表示参数引脚应该隐藏在用户的视图中。请注意,每个功能只能有一个参数引脚以这种方式隐藏

    UFUNCTION(BlueprintCallable, meta = (HidePin = "In_Float"), Category = "Snowing|Parameters")
        void HidePinFunction(int In_Int, float In_Float, FString In_FString, TArray<AActor*> In_TArray);
    • 1
    • 2

    这里写图片描述

  • KeyWords=”Set Of Kwywords”
    指定搜索此函数时可以使用的一组关键字,例如,当放置节点以调用蓝图图形中的函数时

    UFUNCTION(BlueprintCallable, meta = (HidePin = "In_Float", KeyWords = "Hidden Parameter Function"), Category = "Snowing|Parameters")
        void HidePinFunction(int In_Int, float In_Float, FString In_FString, TArray<AActor*> In_TArray);
    • 1
    • 2

    这里写图片描述

  • Lantent
    表示潜在的行动。潜在动作具有FLatentActionInfo类型的一个参数,并且该参数由LatentInfo说明符命名

  • LatentInfo=”Parameter”
    对于BlueprintCallable函数,指示哪个参数是LatentInfo参数

  • MaterialParameterCollectionFunction
    对于BlueprintCallable函数,表示应该使用材质替代节点

  • NativeBreakFunc
    对于BlueprintCallable函数,表示该函数应该以与标准的Break Struct节点相同的方式显示

  • NotBlueprintThreadSafe
    仅在Blueprint函数库中有效。该函数将被视为拥有类的一般BlueprintThreadSafe元数据的异常

  • ShortToolTip
    一个简短的工具提示,在完整的工具提示可能是压倒性的一些情况下使用,如父类选择器对话框

  • ToolTip
    覆盖代码注释中自动生成的工具提示

    UFUNCTION(BlueprintCallable, meta = (ToolTip = "this is tip"), Category = "Snowing|BlueprintFunc")
        float TipFunction();
    • 1
    • 2

    这里写图片描述这里写图片描述

  • UnsafeDuringActorConstruction
    这个函数在Actor构造期间调用是不安全的

  • WorldContext=”Parameter”
    由BlueprintCallable函数使用来指示哪个参数确定操作正在发生的世界

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值