How To define a function with multiple return values as blueprint in C++

Hello, Community!

I am working on some functions that can be used in both C++ and blueprints. I need some functions to be returned with multiple values.
I know I can define a struct whenever I need multiple values to be returned in C++.(Many structs to define …)
Since the blueprint functions can be returned with multiple values, there must be some way that can do the same thing in C++.

I am new to the Engine and C++,please help me out.

Blueprint functions with “multiple” return values are actually just C++ reference parametres to determine what the return values are.

For instance:


UFUNCTION( Category=Foo, BlueprintCallable )
void Foo( const FBar& Bar );

Since the reference is const and the function therefore cannot modify it, Blueprint will treat it as an “in” param. Conversely:


UFUNCTION( Category=Foo, BlueprintCallable )
void Foo( FBar& Bar );

Since the reference is not const, you can modify it in the function, so Blueprint assumes that is the intent and treats it as “out”. Continuing from there, you can have multiple non-const reference params:


UFUNCTION( Category=Foo, BlueprintCallable )
void Foo( FBar& Bar, FVector& Baz, FRotator& Qux );

All of these mutable params will be treated as “out” by Blueprint, resulting in multiple “return” values. This is how engine functions do it.

39 Likes

Thank you, cmartel! I tried a little using the following code and it worked!!!

UFUNCTION(BlueprintCallable, Category = "MyBlueprintFunctionLibrary")
	static void switchValue(const float a,const float b, float &a_out, float &b_out);

void UMyBlueprintFunctionLibrary::switchValue(const float a, const float b, float &a_out, float &b_out)
{
	a_out = b;
	b_out = a;
}

Capture.PNG

Thank you so much!!!

25 Likes

Thanks What I was looking for

Thnaks!!!
I was wondering if there is a way to make the out pins of different datatypes than of inputs.