简书链接:unrealenginec函数常用修饰符用途和案例举例
文章字数:220,阅读全文大约需要1分钟

BlueprintCallable

可以在蓝图中调用 可定义为静态
1
2
3
4
5
6
7
8
9
10
```
class CPPDIGITALTWN_API UEUtil : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION(BlueprintCallable)
static FString GetTime();

}

BlueprintImplementableEvent

此函数只能蓝图或关卡蓝图图表中被覆盖。 (事件中选择重写)
1

UFUNCTION(BlueprintImplementableEvent, Category = "ChangeWeather")
    void switchWeather(int flag);
1
2
3
4
5
```swithWeather```不能在cpp中实现

### BlueprintNativeEvent

``` BlueprintNativeEvent``` 可在蓝图中实现也可以同时 本地实现。c++这边的实现应该定义为函数名_Implementation
//.h file

#pragma once
#include “CoreMinimal.h”
#include “Blueprint/UserWidget.h”
#include “Components/Image.h”
#include “MainUIParent.generated.h”
UCLASS()
class CPPDIGITALTWN_API UMainUIParent : public UUserWidget
{
GENERATED_BODY()

UFUNCTION(BlueprintNativeEvent, Category = "Basic")
    void switchMode();
virtual void switchMode_Implementation();

}
//cpp
void UMainUIParent::switchMode_Implementation()
{
UKismetSystemLibrary::PrintString(this, TEXT(“切换模式被点击了”));
}

### BlueprintPure
``` BlueprintPure```    纯函数
在蓝图中没有引脚  必须有返回值
摘自网络上的描述:
BlueprintPure的特点是在C++和蓝图中都可以调用,但是其修饰的函数必须有函数返回值或
函数参数输出,否则会编译失败。被声明的函数不会以任何方式拥有对象,并且可以在蓝图
或级别蓝图图标中执行。
因此,BlueprintPurs修饰的函数,主要用于(1)数学中的“+、-、*、/”操作  (数值处理)