不常见的函数参数
蓝图参数引用
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);
}
}
}