keyword
prefab
prefab Name: Model { Comp { field: value }, … }
A prefab names a model together with preset field values, so what every spawn of a kind shares is written once: prefab Grunt: Creature { Stats { hp: 30 }, Weapon { def_id: 1 } }. spawn Grunt { Position { x: 40 } } spawns the model with the prefab's presets and then the spawn's own fields on top. Prefabs chain — prefab Grunt: Foe where Foe is itself a prefab — so shared presets live in one place. Field values are ordinary expressions evaluated at each spawn (a preset may read a global such as a loaded sprite id), @OnSpawn(Model) runs as for any spawn of the model, spawn is also an expression yielding the new entity, and Prefab.spawn(name:) picks a prefab by name at runtime.
Example
# doc-check: skip — composite: prefabs plus their spawns
prefab Foe: Creature { Faction { id: 2 }, Body { policy: BodyPolicy.TopDown } }
prefab Grunt: Foe { Stats { hp: 30, max_hp: 30 }, Weapon { def_id: WeaponId.Bite } }
let grunt = spawn Grunt { Position { x: 40, y: 60 } }
let other = Prefab.spawn(name: "Grunt")