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

So I have this function here:

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 .

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:

I have also tried the following:

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

So this should work since it is a struct.

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

Thanks for any help!

Im not brilliant with this but…

if you want to return reference in blueprint I think you want

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…ntNativeEvents

also maybe see this post

hope that helps (and i hope i got that right)

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.

Oh this is sad. :frowning: 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 :p.

Thanks for your help tho, cheers!

Digging out old topic, but for future readers - to add a reference add UPARAM(ref) macro:

UPARAM(ref) FEntityAttribute& GetTargetAttribute() { return targetAttribute; }