annotation
@OnSpawn
@OnSpawn(Model) handler Name { … }
@OnSpawn(Model) turns a handler into a birth hook: it fires once for each newly spawned instance of the named model, right after its properties are seeded. The body runs in the context of that fresh instance, so it can read and adjust the instance's fields by property name to finish initialization — seed derived state, register the instance, play a spawn effect. The model name is a checked reference, so a typo is a compile error rather than a silently dead hook. Its teardown counterpart is @OnDespawn; add @Public to also emit a model_<Model>_spawn event other modules can listen for.
Example
program SpawnHook {
property Health { current: int = 0, maximum: int = 100 }
model Enemy { Health }
@OnSpawn(Enemy) handler InitEnemy { # fires per new Enemy instance
Health.current = Health.maximum # start every enemy at full health
print(Health.current) # 100
}
handler SpawnWave phase Start {
spawn Enemy { Health { current: 0, maximum: 100 } }
}
}