| name | bl-core-lifecycle |
| description | Use for BovineLabs Core initialization or destruction lifecycles, lifecycle groups, ordering, authoring, or world startup and shutdown issues. |
Core Lifecycle
Resolve Core source from Packages/com.bovinelabs.core or its exact Library/PackageCache entry. Prefer lifecycle components and groups over ad hoc initialization or destruction.
Read Order
Documentation~/LifeCycle.md
BovineLabs.Core.Extensions.Authoring/LifeCycle/LifeCycleAuthoring.cs
BovineLabs.Core.Extensions/LifeCycle/InitializeEntity.cs
BovineLabs.Core.Extensions/LifeCycle/InitializeSubSceneEntity.cs
BovineLabs.Core.Extensions/LifeCycle/DestroyEntity.cs
BovineLabs.Core.Extensions/LifeCycle/InitializeSystemGroup.cs
BovineLabs.Core.Extensions/LifeCycle/SceneInitializeSystem.cs
BovineLabs.Core.Extensions/LifeCycle/InitializeEntitySystem.cs
BovineLabs.Core.Extensions/LifeCycle/DestroySystemGroup.cs
BovineLabs.Core.Extensions/LifeCycle/DestroyOnDestroySystem.cs
BovineLabs.Core.Extensions/LifeCycle/DestroyOnSubSceneUnloadSystem.cs
BovineLabs.Core.Extensions/LifeCycle/DestroyEntitySystem.cs
BovineLabs.Core.Extensions/LifeCycle/DestroyTimer.cs
BovineLabs.Core.Extensions/InstantiateCommandBufferSystem.cs
BovineLabs.Core.Extensions/LifeCycle/EndInitializeEntityCommandBufferSystem.cs
BovineLabs.Core.Extensions/LifeCycle/DestroyEntityCommandBufferSystem.cs
Setup Rules
- Add
LifeCycleAuthoring to authored entities that must participate in lifecycle phases.
- For additional baked entities, call
LifeCycleAuthoring.AddComponents(IBaker, Entity, bool isPrefab).
- Prefabs use
InitializeEntity (enabled on bake); subscene entities use InitializeSubSceneEntity (enabled on bake).
- Entities participating in lifecycle destruction must have
DestroyEntity (default disabled on bake).
Initialization Rules
- Place one-shot initialization systems in
InitializeSystemGroup.
- Query with:
[WithAll(typeof(InitializeEntity))] for prefab-instantiated entities.
[WithAll(typeof(InitializeSubSceneEntity))] for opted-in subscene entities.
[WithAny(typeof(InitializeEntity), typeof(InitializeSubSceneEntity))] for both.
- Do not manually disable initialize components;
InitializeEntitySystem (order last) disables them after initialize phase.
Destruction Rules
- In gameplay/runtime systems, request destruction by enabling
DestroyEntity instead of directly destroying entities.
DestroyOnDestroySystem propagates destruction through LinkedEntityGroup hierarchies.
DestroyOnSubSceneUnloadSystem enables DestroyEntity for entities in unloading subscenes.
DestroyEntitySystem performs final destruction in DestroySystemGroup (order last).
- On client worlds with NetCode, ghost entities are excluded from
DestroyEntitySystem destruction queries.
Command Buffer Rules
- Use
InstantiateCommandBufferSystem.Singleton for instantiation-phase structural work.
- Use
EndInitializeEntityCommandBufferSystem.Singleton for deferred commands at end of initialize phase.
- Use
DestroyEntityCommandBufferSystem.Singleton for deferred commands during destroy phase.
- Keep lifecycle commands in these phase systems to preserve ordering and avoid ad-hoc sync points.
Ordering Notes
InitializeSystemGroup and DestroySystemGroup both run in BeforeSceneSystemGroup, after InstantiateCommandBufferSystem.
InitializeSystemGroup runs before DestroySystemGroup.
SceneInitializeSystem (order first in BeginSimulationSystemGroup) explicitly updates InitializeSystemGroup.
- During full pause (
PauseGame.PauseAll), InitializeSystemGroup early-outs.
DestroyTimer Rules
DestroyTimer<T> requires sizeof(T) == sizeof(float).
- Call
destroyTimer.OnCreate(ref state) in system OnCreate.
- Call
destroyTimer.OnUpdate(ref state) each update to decrement timers and enable DestroyEntity at zero.
Failure Checklist
- Initialize logic not running:
- Verify initialize component exists and is enabled.
- Verify system is in
InitializeSystemGroup.
- Entities not being destroyed:
- Verify
DestroyEntity exists and is enabled.
- Verify code is enabling, not just reading, the enableable component.
- Child entities survive parent destroy:
- Verify parent has
LinkedEntityGroup.
- Verify child entities have
DestroyEntity component.
- Timer-based destruction not firing:
- Verify timer component is float-sized.
- Verify
DestroyTimer<T>.OnCreate is called.
- Subscene unload cleanup not happening:
- Verify entities carry
DestroyEntity and belong to the unloading scene section.