【转载】BlueprintCallable 与 BlueprintPure

724 阅读1分钟

原文链接

前言

BlueprintCallableBlueprintPure 标记的函数在蓝图内最明显的区别就是有没有执行引脚

除此之外,BlueprintCallable 函数的返回值会在执行这个函数的作用域(或者说执行流)中创建一个局部变量,而 BlueprintPure 不会

BlueprintPure 函数会在每次需要使用返回值的时候执行一次函数,如果在单个节点内有进行大量计算而且其计算结果会多次使用的话,需要避免使用 BlueprintPure

具体说明可见 官方文档 中的执行流部分

验证

在蓝图函数库中创建一个静态变量和一个静态函数

static int32 TestInt;

UFUNCTION(BlueprintCallable)
static int32 Test01();

int32 UFuncLibTest::TestInt = 0;
int32 UFuncLibTest::Test01()
{
  return ++TestInt;
}

蓝图中调用:

查看 log:

可见函数只调用了 1


BlueprintCallable 改为 BlueprintPure 之后再在蓝图中调用:

查看 log:

可见函数此时调用了 10

相关文章

【转载】BlueprintImplementableEvent 与 BlueprintNativeEvent

【转载】Blueprintable\NotBlueprintTypeEditAnywhere\EditDefaultsOnly\EditInstanceOnly