A pre-placed unit's index you can read in the editor. Every unit matching a condition you can get with a unit loop. But one unit created by a trigger during the game - a respawned hero, a chosen character - fits neither.
0x628438 holds the structure offset of the NEXT unit to be created. Read it immediately before creating, and the unit you then create is the one at that address.
// 만들기 직전에 읽고, 만든다. 순서가 전부입니다. hero = dwread(0x628438); CreateUnit(1, "Protoss Scout", loc, P1); // 이제 hero 는 방금 만든 스카웃의 구조 오프셋입니다.
If the unit table is full the creation fails and the address you saved points at something else. 0x6283F0 is the current unit count, so only create while it is at most 1698. StarCraft's limit is 1,700 and past it you get "cannot".
Holding it is the harder half. When the unit dies its slot is reused by the next unit, and the address you stored now points at a different unit entirely. The address did not change; its occupant did.
The uniquenessIdentifier at +0xA5 exists for this. It increments each time the slot is reused, so storing it alongside the address and comparing on use is what tells apart "the same slot, a different unit".
Never dereference the structure offset of a unit that has died - crash list #9. A stored handle has to be checked before use: if the CSprite pointer at +0x0C is 0, there is no unit in that slot.
Structure offsets