Yan's Studio.

C++生成蓝图的参数类型记录

Word count: 362Reading time: 1 min
2022/10/08

1. 普通参数

在UE C++中寻常函数传参为
UFUNCTION(BlueprintCallable) static void Func1(FString InputStr);

2. 多输出引脚

但是在UE4的C++中,不带Const的引用在蓝图中是默认为输出引脚的,所以可以借此来实现蓝图的多引脚输出。
UFUNCTION(BlueprintCallable) static void Func2(FString& OutputStr);
具体蓝图节点如下

在虚幻官方的蓝图文档中
”在带大量返回参数的函数和返回结构体的函数之间优先前者。“

所以返回大量参数的优先级更高,可以使用Type& Value的方法,使蓝图节点返回大量的参数。
甚至还能使用对指针的引用来返回更多的参数(感觉挺邪门)
UFUNCTION(BlueprintCallable) static AActor* Func5(AActor *& A1, AActor *& A2, AActor *& A3)

3. 带Const的引用

一旦引用带有const,那么他将会变为传入的参数
UFUNCTION(BlueprintCallable) static void Func3(const FString& ConstInputStr, const FVector& ConstInputVector, const int32& ConstInputInteger ) { // ConstInputStr = TEXT(“他不行呀”); // ConstInputVector = FVector::ZeroVector }

FString并不会使用引用,具体也不太清楚为什么!

4. C++到蓝图真正的引用

使用UPARAM(ref)来作为修饰
UFUNCTION(BlueprintCallable) static void Func4(UPARAM(ref) FString& InputStrByRef, UPARAM(ref) FVector& InputVector) { InputStrByRef = TEXT(“Hi”); InputVector = FVector::ZeroVector; }

对传入的引用进行值得修改

运行结果为:

5. 最后来个大杂烩

UFUNCTION(BlueprintCallable) static FVector Func(FVector Input, FVector& Output, const FVector& ConstInputRef, UPARAM(ref) FVector& InputRef) { return FVector::ZeroVector; }

CATALOG
  1. 1. 1. 普通参数
  2. 2. 2. 多输出引脚
  3. 3. 3. 带Const的引用
  4. 4. 4. C++到蓝图真正的引用
  5. 5. 5. 最后来个大杂烩