博客

技术思考、排障与开发记录。

博客/UE开发

UE 蓝图函数参数:引用方向与显示名称

UE C++ 的引用参数在蓝图节点上不一定呈现为预期的输入引脚。声明类型、`const` 和参数元数据共同影响节点表现。以下示例用于 UE5 的反射函数声明,未在引擎中编译。

返回
本页目录

不常见的函数参数

蓝图参数引用

UFUNCTION(BlueprintCallable)
static void DoSomething(UPARAM(ref) TArray<int> &InOutArray);

可以通过在函数中声明引用参数,UPARAM(ref) 来传送蓝图对象的引用,并且在C++中修改 UPARAM参数 必须放在第一个参数位置

重命名蓝图参数

UFUNCTION(BlueprintCallable)
void MakeDog(
  UPARAM(DisplayName = "Years (dog years)") float Years,
  UPARAM(DisplayName = "Fur Color") FLinearColor Color);

允许传入抽象值

UFUNCTION(BlueprintCallable, Category = "Composure", meta = (DeterminesOutputType = "OutputType"))
UCompositingElementOutput* FindOutputPass(UPARAM(meta = (AllowAbstract = "true"))TSubclassOf<UCompositingElementOutput> OutputType, FName OptionalPassName = NAME_None);

类限制

UFUNCTION(unreliable, client, BlueprintCallable, Category="Game|Feedback")
void ClientSpawnGenericCameraLensEffect(UPARAM(meta=(MustImplement ="CameraLensEffectInterface")) TSubclassOf<class AActor>  LensEffectEmitterClass);

Lambda函数传递

示列

void FXvpInputActionSet::ForEachAction(const TFunctionRef<void(FXvpInputActionBase*)>& Fn)
	{
	for (auto Property = GetStructType()->PropertyLink; Property; Property = Property->PropertyLinkNext)
		{
			if (const auto StructProperty = CastField<FStructProperty>(Property))
			{
			const auto ActionPtr = StructProperty->ContainerPtrToValuePtr<FXvpInputActionBase>(this);
				Fn(ActionPtr);
			}
		}
	}