annotation
@OnDetach
@OnDetach(Property) handler Name { … }
@OnDetach(Property) is the teardown counterpart to @OnAttach: it fires when the named property is structurally removed from a live instance with detach P on e. The hook runs before the property's presence flag clears, so its body can still read the outgoing field values one last time — useful for releasing whatever the property was tracking or logging its final state. It is distinct from @OnDisable, which pauses a property while keeping its data; detach actually destroys the property's presence on the instance. Add @Public to also emit a prop_<Property>_detach event.
Example
program DetachHook {
property Tag { value: int = 0 }
property Shield { amount: int = 0 }
model Unit { Tag }
@OnDetach(Shield) handler DropShield { # fires as Shield is removed
print(Shield.amount + 20) # 25 — reads the outgoing amount
}
handler Seed phase Start {
spawn Unit { Tag { value: 1 } }
for (unit) in query [Unit] { attach Shield on self() { amount: 5 } }
}
handler RemoveShield phase Render {
for (shield) in query [Shield] {
detach Shield on self() # triggers @OnDetach
}
quit()
}
}