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"

Blueprint TMap 'Find' not returning values by reference

It seems as if the 'Find' node for the newly released TMap container does not return values by reference (Though I believe it is meant to). A quick way to check this is to create a TMap with any key or value type (I used Integer, Integer), and then run the following functions:

alt text

After doing so, you can check the value of key 0, and it will still be 0, despite incrementing it with the IncrementInt macro. I would imagine it is intended to be returned by reference (For obvious reasons), but if it was not intended that way, I would like to put this in as a feature request.

Product Version: UE 4.15
more ▼

asked Feb 24 '17 at 01:29 PM in Bug Reports

avatar image

638 15 21 63

avatar image TJ V ♦♦ STAFF Feb 24 '17 at 10:09 PM

Hi Jamendxman3,

Thank you for the report. I was able to reproduce this behavior so I've entered JIRA UE-42388 and our developers will be investigating further. Follow that link to monitor the status of the report.

I did notice something odd that I mention in the report. Adding a key of 1 instead of 0 will allow the 0 key to be incremented.



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

-1 answers: sort voted first

It's intentional that Find (and array Get) returns a copy - but we would like to improve this. UE-6451 is the highest profile bug that is affected by this core behavior - and I spend a lot of time thinking about it.

The reason for this behavior is that we can't safely return a reference to data thats owned by a container type. Consider this blueprint:

Undefined behavior blueprint

My current best idea (and there may be other approaches!) is to augment the VM so that we can safely track these references and throw an exception if later statements attempt to access container memory that was freed by subsequent statements.

It's very important to us that blueprints not hard crash the UE4 process - but if this behavior is not important to you it's relatively easy to make these nodes return an unsafe reference. A related codepath is associated with the EX_ArrayGetByRef instruction identifier.


We did a little digging and the potentially stale reference above is not possible because the reference output pin results in a re-evaluation of the input expression (meaning in the example above we call NewVar1.Get(0) twice and the second time would simply fail with an out of bounds exception.

This is great news - we're hoping to provide an array Get node that returns a reference in 4.16. A Map::Find node may also make that binary release.

Edit2: by passing the reference to a function you are able to crash the blueprint runtime. We are back to square one on this front. We want blueprints to be safe, fast, and easy to use. That is a rough guide to our priorities and dominates priorities in this case.

more ▼

answered Feb 28 '17 at 10:13 PM

avatar image

Dan.OConnor STAFF
495 14 7 17

avatar image mikeyj21 Sep 03 '17 at 04:53 PM

Hi! Did this ever happen? I can't find a Get node returning a reference; every time I have to use the 'Set members then add it back to the map at the same key' paradigm, a little part of me cries....

avatar image Varden4224 Sep 28 '17 at 08:32 PM

I am also looking forward to an improvement on this side. because I do not see how I can call an own function has an object stored in an array if all that I get is a copy ... the only solution in my eyes is to go through a foreachloop ... but that does not seems an effective way to me ... would I miss something?

avatar image Dan.OConnor STAFF Sep 28 '17 at 08:49 PM

As of 4.16 there is a toggle on Array Get nodes that allow it to return by Ref. The problematic blueprint I described above is actually not a problem because we call the Get function again on subsequent accesses, giving us a chance to ensure that the range is valid.

avatar image Legionarus Nov 23 '17 at 01:09 AM

Just wondering if this change is also going to be done to the Map's Find function, because it is still very frustrating dealing with structures in maps, and I imagine also a bit expensive. Is it planned for any release?

avatar image Dan.OConnor STAFF Dec 01 '17 at 07:10 AM

It's not currently slotted for a release. I'll see if we can get this on the schedule.

avatar image KristofMorva Mar 24 '18 at 03:36 PM

Any chance it can be included in 4.20 at the latest? Would be very useful for us too for map of structs.

avatar image Smurfies Jul 31 '18 at 04:58 AM

Any update on Map's get Function being added?

avatar image ShannonGreenwood Feb 15 '19 at 02:12 AM

An update would be great! I keep asking myself, is this really necessary? - but this thread indicates that it is.

avatar image Dan.OConnor STAFF Feb 15 '19 at 02:16 AM

I actually discovered that it was somewhat easy to segfault the runtime using array values passed by ref. That discovery shifted priorities. Unfortunately, making array access safe is a higher priority than allowing unsafe access to map values.

(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