User Tag List

Results 1 to 3 of 3

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

  1. #1
    1

    Question 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.

  2. #2
    3
    Blueprint functions with "multiple" return values are actually just C++ reference parametres to determine what the return values are.

    For instance:

    Code:
    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:

    Code:
    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:

    Code:
    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.

    -Camille

  3. #3
    1
    Quote Originally Posted by cmartel View Post
    Blueprint functions with "multiple" return values are actually just C++ reference parametres to determine what the return values are.

    For instance:

    Code:
    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:

    Code:
    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:

    Code:
    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.

    -Camille

    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;
    }


    Name:  Capture.PNG
Views: 6101
Size:  15.8 KB

    Thank you so much!!!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •