Reordering Maps ( dictionary)

Bit late to the party but I also had some trouble finding help with this topic. I’ve attached a screenshot of my solution which in hindsight, seems pretty obvious/straight forward.

  1. Start with a While Loop to iterate through the list until done
  2. I wanted to sort the “Values” of this map so use the Max of Int Array to grab the highest value entry in the Map
  3. Using that node, also grab the index of that entry which you’ll need shortly
  4. Now use the Get node and the previously grabbed Index value to make sure you’ve got the correct entry in the map.
  5. Now you just shove it into a new Map (local variable) using the index to make sure you’ve got the right entry. You’re basically just copying the Key and the Value straight into a new temporary map.
  6. Once its shoved in the new map, remove it from the original map so that the While Loop iterator can eventually finish once the Map is emptied.
  7. Extra spice, reason I was sorting was so they could be added to a scrollbox list in an Editor Utility Widget. Using a similar method of grabbing the data, I could then feed the new sorted list in order as child widgets of the scrollbox.

Hopefully someone finds this helpful. Shout out if something doesn’t make sense :slight_smile:

2 Likes