Skip to main content

Module lifecycle

Module lifecycle 

Source
Expand description

Lifecycle behaviour components: callbacks that run when an entity is spawned or despawned.

These are components, not hooks into a scheduler: the callbacks live in the entity’s own row and the world runs them at the structural change that produced or is about to remove it. There is no change detection and no deferred pass – an OnDespawn callback runs while the entity still has its components, because afterwards there is nothing left to read.

A callback gets the scope of the entity’s own scope, which is its parent, and cannot change the world’s structure: it queues those changes instead. The callback is taken out of the entity’s row for the run and put back after, so a callback that reaches for its own lifecycle component reads the row rather than finding it held open by its own run.

Re-exports§

use crate::entity::Entity; 🔒
use crate::view::Scope; 🔒

Modules§

sealed 🔒

Macros§

lifecycle_component 🔒
Declare one lifecycle component: its callback and its constructor.

Structs§

OnDespawn
The callback that runs right before the entity is despawned.
OnSpawn
The callback that runs right after the entity is spawned.

Traits§

Lifecycle
A component whose callback the world runs at a structural change.

Type Aliases§

LifecycleCallback
The callback of a lifecycle component.