No value will be Returned by Reference using delegates

Hello there! I am facing a problem in my project. Everytime I use Event Dispatcher using array arguments i get this message that appeared in my cases on answerhub (using interfaces, etc etc). When i get a value from the dispatcher that variable isn’t a reference, its a copy. If i make changes to her it will not transfer to the original one.

REPRO STEPS

  1. Go to Level Blueprint or any other Blueprint Graph.
  2. Make a Event Dispatcher with a Array Argument
  3. On begin play assign this dispatcher on a custom event
  4. Call it right away using a variable connected to make array node {0}
  5. When the custom event fires, get that first element and change it (it can be a bool, int, user structure)
  6. Print that variable from step for to check if the value changed.
  7. The value continues the same

Apparently i can’t get references even from single variables even in c++

It was supposed be by design, the dispatchers were meant to be one-way communication only - I did read a post by Epic staff about it. However, it does work absolutely fine for objects…


I’m 99% sure the problem here has more to do with passing an array of structs through a custom event - this has always returned a copy, rather than a reference even if you specifically ask for one - like you did with your fancy diamond shaped icon.

So now you’d need to find a way to Set the data here and then push it back into the original array - which I assume will not sit in the same blueprint.


You could try Setting Member In Struct but somehow I feel it will not work anyway.

Yeah you are right, even using a set Struct by reference I still no way to set it’s reference on Dispatcher call…maybe if I change the Struct by an object I can get a different result? I will try this later!

Yeah you are right, even using a set Struct by reference I still no way to set it’s reference on Dispatcher call…maybe if I change the Struct by an object I can get a different result? I will try this later!

If you pass an object that has a struct inside, (you can pass an actor component - much lighter), it should work.

Thank you! i I have made two tests:

  1. (In LevelBp)I made the UObject class with a structure, added a name to its property “Wonderful” and printed it to make sure the name was set properly. Called my delegate and in the same graph changed the struct property and printed the original value name to check if it changed. It worked!

2)(In ActorBp) i made the delegate, created a var and printed its name. Called the delegate after a few seconds. In LevelBp I bind that delegate, changed the structure. After more 3 seconds on ActorBp i printed the original value and name has changed just like expected.

The only thing that i thought it was weird is the message still there “No value will be returned by reference” and yet I could change the custom event’s Array Element Structure and it reflected to the original var. If this isn’t “return by reference” I don’t know what it is!

I think that label is misleading. I have it as well in my project and everything is firing as expected.

Thanks for taking the time and putting it to the test!