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!
Saragan
(Saragan)
2
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
https://wiki.unrealengine.com/Bluepr…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.
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!
zompi2
(zompi2)
5
Digging out old topic, but for future readers - to add a reference add UPARAM(ref) macro:
UPARAM(ref) FEntityAttribute& GetTargetAttribute() { return targetAttribute; }
7 Likes
I came to this too, but what if you need to output two structures as links?
UE5.3 here but this actually doesn’t work. The node may have a diamond shaped return pin but internally it’s still returning a value.
Did you ever manage to find a solution to this problem?