Hey there, afaik currently there is no built-in functionality for that. You can get the keys array and the values array, but you can’t get them both in blueprints (only in c++).
I’ve noticed that TMaps are new, they have been making a lot of changes to variables such as Set-by-Ref, fixes for structs, adding Maps and such.
Having simple and clean blueprints is good for our sanity, as it reduces the chance for bugs and allows for quicker understanding when skimming over bp’s
Problem is, the class for the pairs isn’t going to work with blueprints either. Why can’t you just get the array of keys and the array of values? I would hope they’d be correlated so you can iterate through both with the same index.
TMaps dont really follow the rule because they use TPairs which is not very supported with blueprints, you can’t even create normal variables of TPair. So you have to ask epic to add that support.
But it’s an array of an unsupported type, if they don’t add support then that would mean that they would have to make a use case just for tpair so that the for loop would have 2 outputs, one for the key and one for the value.
So you’d have a “For each pair Loop” that had three item outputs instead of two: an index, a key, and a value. You still need to specify the types for the key and value – not at runtime for the game, runtime for the editor (that was a little ambiguous, sorry).
The thing is, there is no support for this, so you either use what you have or you ask epic do add it. A few versions ago we didn’t even had TMap support, so it’s slowly getting there.
Or you add it yourself and do a pull request on Github. And the pairs are unsupported but it doesn’t matter because we are talking about C++ code that implements a blueprint library node (“ForEachPairLoop” wouldn’t provide the pair to the blueprint, it would provide the key and value).
I found the Select node code. I can see the “Autowire” stuff that configures the output pin types based on the input pins. For reference, the code is in “\Engine\Source\Editor\BlueprintGraph\Private\K2Node_Select.cpp”.
That means you’d have to override the Map wrapper functionality – which means a different kind of difficulty and more trouble keeping the PR free of conflicts while you wait for approval. A BP library node (external to the Map wrapper class) would be much smoother. And with an external node, you can’t know the types til you have the input pin set. Heck, with the library node, you don’t even need to make a PR, you can just use it and share the function – or stick it in a plugin for others to use.
Old threat, but just for people (like myself) coming across this now - you can get an array of keys from the map variable in blueprints as well now. So you can create a foreachloop with that and find the associated values for those keys.
For sake of efficiency you would want to get the MAP size, and then iterate through it. Otherwise you access the data twice, once to get the array of keys, and again to access each value. If you do this a lot, this would be 2x the cost roughly.