Announcement

Collapse
No announcement yet.

[Bug?] Can't return a struct reference from BlueprintCallable function.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Bug?] Can't return a struct reference from BlueprintCallable function.

    So I have this function here:

    Code:
    UFUNCTION(BlueprintCallable, BlueprintPure)
    FEntityAttribute& GetTargetAttribute() { return *targetAttribute; }
    I'd like to have it return a reference to FEntityAttribute, but in BP it returns a value .
    Click image for larger version  Name:	Screenshot_1.png Views:	1 Size:	19.1 KB ID:	1572303

    The output pin should have the diamond shape (by-ref type), not a circle (by-value type), like the input and output pins of Set members in struct:
    Click image for larger version  Name:	Screenshot_2.png Views:	1 Size:	26.3 KB ID:	1572304

    I have also tried the following:
    Code:
    UFUNCTION(BlueprintCallable, BlueprintPure)
    void GetTargetAttribute(FEntityAttribute& out) { out = *targetAttribute; };
    This not only generates a circle pin (by-value) but also crashes the engine when the node is executed.

    I've seen this question on AnswerHub where Sn_a_ke said
    Blueprints do not allow referencing a variable's memory location if the variable is not UCLass USruct or UEnum (I hope I correctly formulated)
    So this should work since it is a struct.

    This is most probably a bug, isn't it?

    Thanks for any help!
    Last edited by ItsaMeTuni; 01-14-2019, 12:40 PM.
    C++ is awesome

    #2
    Im not brilliant with this but...

    if you want to return reference in blueprint I think you want
    Code:
    FEntityAttribute& GetTargetAttribute() { return targetAttribute; }
    if you want a pointer i think you want return a type FEntityAttribute* not FEntityAttribute&

    i believe blue print function parameters need to be const FEntityAttribute& out I think as well for your second try

    this seems to show an example of native with a pointer
    https://wiki.unrealengine.com/Bluepr...ntNativeEvents

    also maybe see this post
    https://answers.unrealengine.com/que...t-funcion.html

    hope that helps (and i hope i got that right)
    Last edited by Saragan; 01-15-2019, 05:43 AM.

    Comment


      #3
      Originally posted by Saragan View Post
      Im not brilliant with this but...

      if you want to return reference in blueprint I think you want
      Code:
      FEntityAttribute& GetTargetAttribute() { return targetAttribute; }
      Yeah, this should work, but it doesn't. As you can see I tried this already and I get a value in BP, not a reference.

      I'd like to use a pointer, but struct pointers aren't allowed in BP. So I'm just trying to return a reference to the value that my pointer points to.

      Originally posted by Saragan View Post
      i believe blue print function parameters need to be const FEntityAttribute& out I think as well for your second try
      Oh this is sad. A const reference parameter won't do much help since I need to modify the referenced value in BP.

      Well, I guess I'm gonna have to use a setter function then .

      Thanks for your help tho, cheers!
      C++ is awesome

      Comment


        #4
        Digging out old topic, but for future readers - to add a reference add UPARAM(ref) macro:
        Code:
        UPARAM(ref) FEntityAttribute& GetTargetAttribute() { return targetAttribute; }

        Comment

        Working...
        X