API Reference › Entities & the ECS › world_attach_dyn
function

world_attach_dyn

world_attach_dyn(target, property)

world_attach_dyn adds a property to a live instance by numeric id, the reflection-ABI counterpart of the static attach Prop on instance. It is the tool a mod uses to grant a runtime-registered property (from world_register_prop) — or any property known only by id — to an instance, after which the instance's fields can be written with world_set. It returns nothing and sets the instance's has-flag for that property. Pair it with world_detach_dyn to remove. In ordinary compiled code, prefer the attach statement, which also fires @OnAttach hooks and seeds field overrides.

Parameters

targetthe model instance to modify, an entity handle
propertythe property id to attach, from world_prop_id or world_register_prop

Example

program GrantComponent {
  property Position { column: int = 0, row: int = 0 }
  model Player { Position }

  handler Boot phase Start {
    spawn Hero { Position { column: 4, row: 4 } }
    let stamina_property = world_register_prop("Stamina", 1)
    for (position) in query [Position, {Player}] {
      world_attach_dyn(self(), stamina_property)
    }
  }
}
← All symbols