I have a Custom Event with an int parameter passed by reference. I call my custom event with an int variable linked to this parameter. Inside the event I use “Set int (by ref)” node to modify the value of the parameter. It modifies the value inside the event blueprint, but not in the caller blueprint.
Reference variables on events are fine, but it does look like there’s a bug here. I just tried locally, and got the same results. I’ll log the bug to get it fixed up; both events and functions should treat reference parameters the same! Thanks for the report!
Apologies for the necro; couldn’t find any other topics that directly address this.
Looks like the last two official responses are somewhat in conflict with each other, and I’m getting warnings trying to pass-by-ref through a custom event. Did you guys end up going with Marc’s answer or Nick’s?
Pass-by-ref does not work in 4.16.1 for Custom Events with Custom Structs either. It never has, which I’ve always believed was an intentional ‘feature’. (even though it seems like an option)
Using functions for this is not an option for you I assume.
I’m having this issue in 4.18.3. I have a blueprint function (not event) which accepts a Scene Component object reference. Passing it by ref will result in nothing being passed, but passing by value works fine. I enabled/disabled passing by ref several times, and it consistently failed by ref.
I also can confirm it is not fixed in 4.19. You can reproduce this by adding a custom event and making one of its inputs passed by reference (except arrays, strange !)
I just ran headfirst into this bug in a bizarre situation: Subclassing.
So
void BPBaseClass::Test(UParam(Ref) FStruct& A)
is a function in BPBaseClass Everything works fine, “FStruct& A” is passed successfully.
Now if we override Test() in BPSubClass, that function gets turned into an Event since it does not have a return value (WHY?? EPIC WHY??), which breaks because “FStruct& A” cannot be passed by ref in Event.
And that took me a whole day to debug and fix up everything in the subclass chain. Seriously, fix up this inconsistent **** will ya.
This is still happening in 4.25, sadly. I wanted to make a tweening Library in C++ and expose it to Blueprints by having two custom events, a getter and setter (just like Unity’s DOTween). Since Events can’t return anything, I used a by-ref float variable to “return” the value to the C++ tweening function, but I’m only getting zero.
4.26.0: same issue, but we took a step back since it doesn’t return a warning like in 4.25 (but now the pins are round shaped instead of squared). Please, remove the “pass by ref” checkbox form events if implementation is not planned.
But it’s a local event, is there really the need for pass by reference? You can always set a variable by reference if you must:
Or use a function instead. [HR][/HR]
Events support latent actions, imagine what would happen if you pass-by-ref to an event from another blueprint, the event fires a delay, the original actor gets destroyed. You’ll be* accessing none* after the delay.
Not advocating for artificial limitations, but blueprints do that all the time. It’s already a tangled mess.
@Gustave_404
Could you describe a scenario where this could be useful and safe to use?
Pardon for necro-posting, but I thought I had a reply for this.
Hope I understood the question: Ihave a situation where I’m finding it difficult to get around without pass-by-ref in custom events.
To start, I’m using TCPSocketConnection (a 3rd-party plugin) which I’m using to connect to TCP server which returns some results based on queries that I send it.
TCPSocketConnection utillises event delegates. When it connects to the server via its OnConnected event, the OnMessageReceived delegate is called when the server returns a message. I’d like to store the return based on the command I sent; different variable for a different command.
If pass-by-ref worked in custom events, I would be able to neatly create any number of functions that have a command string and a ref-var. Both will be dispatched to the TCP connection which stores the returned value by ref-var.
This graph shows where I got to before I realised pass-by-ref didn’t work for custom events.
I’m needing to use a timeline in my Event, seen as you can’t use Timelines in Functions or Macros, I have to use a Custom Event.
The fact that you ‘might’ use a Delay in an event is irrelevant, that is up to you to sort out another check to see if the ‘possibly destroyed’ actor is still valid after the delay, like you would before preforming any action on another actor.