UE4 BlueprintCallable与BlueprintPure
被BlueprintCallable和BlueprintPure标记的函数在蓝图内最明显的区别就是有没有执行引脚
除此之外,BlueprintCallable函数的返回值会在执行这个函数的作用域中创建一个局部变量,而BlueprintPure不会
BlueprintPure函数会在每次需要使用返回值的时候执行一次函数,如果在单个节点内有进行大量计算而且其计算结果会多次使用的话,需要避免使用BlueprintPure
具体说明可见 官方文档 中的执行流部分
验证:
在蓝图函数库中创建一个静态变量和一个静态函数
static int32 TestInt;
UFUNCTION(BlueprintCallable)
static int32 Test01();
int32 UFuncLibTest::TestInt = 0;
int32 UFuncLibTest::Test01()
{
return ++TestInt;
}
在蓝图中调用:
查看log:
可见函数只调用了一次
把BlueprintCallable改为BlueprintPure之后再在蓝图中调用:
查看log:
可见函数此时调用了10次