x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

alt text

Product Version: UE 4.21
Tags:
capturar.png (259.2 kB)
more ▼

asked Mar 06 '19 at 02:23 AM in Using UE4

avatar image

Murras
16 1 2

avatar image Murras Mar 06 '19 at 02:57 AM

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

avatar image Everynone Mar 06 '19 at 08:37 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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!

more ▼

answered Mar 06 '19 at 09:22 AM

avatar image

Murras
16 1 2

avatar image Murras Mar 06 '19 at 09:23 AM

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!

avatar image Everynone Mar 06 '19 at 09:48 AM

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

avatar image Murras Mar 06 '19 at 07:17 PM

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.

[1]: /storage/temp/270488-aaaa.png

aaaa2.png (172.2 kB)
aaaa.png (132.3 kB)
avatar image Murras Mar 06 '19 at 07:19 PM

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!

avatar image Everynone Mar 06 '19 at 07:33 PM

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!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question