An overlay is a second graphic that rides on a unit. The first idea is to park another unit on top, and it is wrong for three reasons.
- An EUD map has 1,700 unit slots, half of classic's 3,400. One overlay per unit does not scale.
- A unit dressed as an overlay neither attaches nor animates: you re-position it every frame yourself.
- Several kinds of overlay means spending unit types, of which there are 228.
Cheap overlays make StarCraft itself own the overlay, by borrowing a place where the engine already attaches and plays a graphic. The easiest is the spell overlay: the Defensive Matrix bubble, the green of Ensnare, the glow of Irradiate all come from one byte of status timer.
Usually setting the timer is all it takes, and it costs nothing. The catch is that a timer set on a unit already on screen does not always attach its overlay - and the trick for that is burrow and unburrow. Spell overlays are deleted on burrow and recreated on unburrow from the unit's current state, so setting the timer and then issuing an unburrow redraws it on the spot. The unburrow order has no requirements, so it works whatever the race.
A transform clears any overlay on the unit. If you use both, transform first and attach the overlay second: the other order loses the overlay silently.
The spell overlay is not the only borrowable slot. The Shield Battery's recharge order - order 66 - creates its charging overlay at state 2. This is the weakest of the routes, though: the overlay vanishes the moment the unit is not charging, so it has to be re-applied every frame, and a charging unit cannot move. As an overlay it is not worth it.
The same order's state 3, though, is useful on its own. It is the recharge itself, and the game only checks that charger and chargee share a race - which self versus self satisfies trivially, so it recharges a Terran or Zerg unit's shields too. The better part is that it comes with its own budget: every unit is created with 50 energy whether or not it is a spellcaster, but a non-spellcaster never regenerates energy. So it recharges a fixed amount and then stops for good - a self-heal that is once per life, for a set amount, with no state to track.
Recolouring one unit is the same kind of free overlay. It was long held to be impossible - colour follows ownership - and it is not. What the renderer reads is not the unit but the SPRITE's own player field at CSprite + 0x0A, and that field can be written independently of who owns the unit. One write and that single unit changes colour while its owner does not.
const sprite = dwread_epd(u + 0x0C/4); // CUnit 0x0C → CSprite SetMemoryXEPD(EPD(sprite) + 0x08/4, SetTo, colour << 16, 0x00FF0000); // 0x0A
And the stock twelve are not the limit: the player-colour ramp lives at 0x581D76 + 8 * playerId and writing it gives arbitrary colours. Put the two together and you can mint a thirteenth colour once and then write its index onto only the sprites you want - one boss in gold, infected units in purple - spending neither a unit type nor a player slot.
TransformThe five pools the engine draws from