Iterating a map: Key->Value Syntax and the Manual Counter
The same "give me one extra" iteration form hands you a numeric index for arrays — but a key for maps. Want to know "which number is this?" while walking a map? The official docs offer no shortcut — this page lays out the asymmetry (in Blueprints it is exactly the difference between For Each Loop (Array) giving you Index and For Each Loop (Map) giving you Key), plus the community-blessed workaround.
1. Same Arrow, Two Different Harvests
Lesson 14 covered indexed array iteration (the Array Index pin of Blueprint's For Each Loop (Array)), counting from 0. Maps have the same "give me one extra" form: for (Key -> Value : Map): — but watch out: the extra here is the key, not a sequence number, matching exactly the Key pin of Blueprint's For Each Loop (Map). The form looks identical, the meaning is entirely different: an array's "addresses" are naturally numeric indexes, while a map's "addresses" are keys you chose yourself (strings or integers) — so of course what arrives is the key.
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }
shop_device := class(creative_device):
# Shop price list: keys are item names, values are prices
Prices:[string]int = map{"Potion" => 50, "Wooden Sword" => 120, "Gold Pouch" => 300}
OnBegin<override>()<suspends>:void =
for (Name -> Price : Prices):
Print("{Name} sells for {Price} gold")
Node-for-node translation: Prices is a price list (a Blueprint Map with item names as keys and prices as values). This snippet is a For Each Loop (Map): each round takes the item name Name from the Key pin and the price Price from the Value pin, and Print String formats them as "__ sells for __ gold".
In this code Name walks through the item names in turn and Price is the matching price. Convenient — but what if the requirement is "print item No. 1, No. 2, No. 3"? The sequence number that array iteration hands you for free? On the map side — it does not exist.
2. Want a Sequence Number? No Official Shortcut — Count It Yourself
This is not you failing to find the node. Someone asked on the Epic developer forums whether a for over a map can also hand out a running number — the thread has zero replies to this day. Neither the docs nor the community have a built-in answer, because one genuinely does not exist. The workable approach is the humble trick the poster wrote down themselves: create a counter variable outside the loop, add one to it by hand each round inside the body.
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }
counted_shop_device := class(creative_device):
Prices:[string]int = map{"Potion" => 50, "Wooden Sword" => 120, "Gold Pouch" => 300}
OnBegin<override>()<suspends>:void =
# Map iteration has no built-in index: counter outside the loop, manual +1 inside
var Counter:int = 0
for (Name -> Price : Prices):
set Counter += 1
Print("Item {Counter}: {Name} sells for {Price} gold")
Node-for-node translation: create an integer variable Counter = 0 outside the loop (a Blueprint Integer variable); each round of the For Each Loop (Map) first bumps Counter with a Set node (set Counter += 1), then Print String outputs "Item __: __ sells for __". This is exactly the old Blueprint routine of pairing a ForEach with a hand-rolled counter variable.
Two details worth noticing. First, set Counter += 1 (that Set node) belongs in the loop body — do not shove it into for's parenthesized filter. The filter must be try-then-take-back safe; putting an "it happened, it counts" Set in there either earns an effects error (Compile goes red) or gets taken back along with a failed round — a bump for nothing, pure confusion either way. Second, this counter counts "rounds that actually ran": if the for carries a filter, skipped rounds do not add one, so the numbering stays contiguous — which usually suits you perfectly.
3. Can You Trust the Order? Test Before You Depend on It
One last natural question: in what order does map iteration emit these key-value pairs? The common observation is that it matches insertion order — but be careful: the official docs never write iteration order down as a hard promise, and relying on it is like betting your gameplay on a handshake deal. If your gameplay (leaderboards, shop ordering) relies on a deterministic order, two safe plays: either test it once in your actual target version first, or do not gamble at all — gather all the keys into an array first, sort them however you need, then look each one up in the map by key (Blueprint's Map Find node). From then on the order is in your own hands.
And do not forget Lesson 14's "snapshot": for honors what the map looked like the moment it started — even if you use a Set node inside the loop body to push new key-value pairs into that same map variable, the ongoing iteration will not budge.
4. Pop Quiz
When you iterate a "keys are text, values are integers" map with For Each Loop (Map), what is the extra output K?
Sources
Compiled from the Epic developer forums and the official documentation: Iterate map variable in a for loop and index counter ↗ and Array in Verse ↗.