C++ reference parameter is return value in Blueprint

Hello,

I have a small problem where I have a static function in a class inherited from UBlueprintFunctionLibrary which should enable Blueprint graphs to set a variable in a structure. The function declaration looks as following:
UFUNCTION(BlueprintCallable, Category = Loadout)
static void SetLoadoutSlot(FLoadoutStruct & Data, uint8 SlotIndex, const FLoadoutSlotStruct & Slot);

Now the problem is that because the Loadout paramter is passed by reference, the engine thinks that it is supposed to be an out parameter so the blueprint node looks like this:

52308-screenshot.png

Is there a way to tell the engine not to use the parameter as an output value or do I have to return a new structure instance with this function every time I modify a value in it?

1 Like

Hi,

looks weird that first input param shows in blueprint as output, try add another one before it like

UFUNCTION(BlueprintCallable, Category = Loadout) static void SetLoadoutSlot(uint8 EmptyParamTest, FLoadoutStruct & Data, uint8 SlotIndex, const FLoadoutSlotStruct & Slot);

will EmptyParamTest become output pin then?

p.s. don’t forget mark question as answered with little gray circle button under any answer (not comment, but whole answer) when problem solved, so anyone else later can have same question and may find solution faster, if you find solution on your own, don’t forget write it too

Hello, my problem here is that a parameter passed by reference will be exposed as an output value in blueprint. For functions like
void GetTransforms(FVector & OutLocation, FRotator & OutRotation)
this makes sense, but in my case I want to modify a structure instance and therefore need a non const reference! It would be great if you had to specify which parameters are output values in the UFUNCTION macro or only use parameters as output which start with “Out”.

Edit: And yes I tested it with an additional uint8 parameter as the first one, which will be a usual input in blueprint and the reference is still an output.

I knew I’d read some way of doing this but it took me ages to finally find it again. This should really be properly documented. Anyway, here you go.

UFUNCTION(BlueprintCallable, Category = Loadout)
static void SetLoadoutSlot(UPARAM(ref) FLoadoutStruct& Data, uint8 SlotIndex, const FLoadoutSlotStruct& Slot);
5 Likes

Thanks a lot kamrann! Exactly what I was looking for! I think they should add this to the UFunction documentation page so it is easyer for people to find it.

Yep, same here, it would have taken me quite a while to figure this one out, thanks for digging it up for us.

Thanks man, really helps!

I love you <3