Iterate TMap Elements in Blueprints [4-26]

Hi all,
I need to iterate through a Map’s Elements in blueprints (I need it to be a map so I can look up the values via Name keys later). After searching through several posts and guides, I’ve put together some C++ code that I thought would do the trick, but didn’t work out the way I thought it would:

The resulting blueprint node has the correct inputs and outputs:
maploop_bpnode
But it looks like ExpandEnumAsExecs only affects execution after the function has finished, so the loop never happens.

I’ve been trying to avoid doing something like this:


because I think this is bad code- iterating through key:value pairs directly is likely more efficient.

So, since ExpandEnumAsExecs appears to be out of the question, there must be some other way to create a loop in C++ that can be “hooked into” in Blueprints, right? If there’s a way to do it strictly in blueprints that would be fine too.

But it looks like ExpandEnumAsExecs only affects execution after the function has finished, so the loop never happens.

ExpandEnumAsExecs is basically a Switch statement on the resulting enum. You can’t use it like you did.

If, instead of Keys/Find you first query both Keys and Values as arrays, and Get latter by the index in the loop, that should be probably more efficient than your BP example.

If you would like to do it properly, you’ll probably have to set up your own custom Blueprint node; for this, you can look into UK2Node (you’ll find quite some examples for it in the engine source code), but it’s a more involved undertaking.

1 Like

Sounds good, will look into making a custom UK2Node for this, thanks