API Reference › Entities & the ECS › world_spawn
function

world_spawn

world_spawn(model) -> entity

world_spawn creates a new instance of a model chosen by numeric id and returns its entity handle — the reflection-ABI counterpart of the static spawn Label { … }. Because the model is given as an id (from world_model_id) rather than a name written in source, a mod or tool can decide at runtime which kind to create. The new instance is seeded exactly as the static spawn would seed it — every property in the model attached with default field values — after which you can set fields with world_set. Use the ordinary spawn statement in normal handler code; reach for world_spawn when the kind is data, not a literal.

Parameters

modelthe model id to instantiate, from world_model_id

Example

program Reinforcements {
  property Position { column: int = 0, row: int = 0 }
  model Enemy { Position }

  handler Reinforce phase Update {
    if Input.key() == ' ' {
      let enemy_model = world_model_id("Enemy")
      let new_enemy = world_spawn(enemy_model)
      Screen.status(string(new_enemy))
    }
  }
}
← All symbols