Entity Baking
Entity baking converts authoring data into ECS runtime data. The Behavior Tree component includes a baker, so an enabled tree is baked with its GameObject or prefab; you do not need to convert its tasks manually.
Choose when the tree starts
If Start When Enabled is enabled on the Behavior Tree component, a baked tree starts automatically when its entity becomes available. This is the usual choice for agents that should begin immediately after a subscene loads or a prefab is instantiated.
If Start When Enabled is disabled, the entity is created with a deferred start. Start that specific tree when your gameplay is ready:
BehaviorTree.StartBakedBehaviorTree(world, entity);
The method returns true when it starts the deferred tree. Calling EnableBakedBehaviorTreeSystem is no longer required; baked startup now runs automatically.
Spawn baked behavior tree prefabs
Put the Behavior Tree component on the prefab and reference that prefab from an authoring component in a subscene. Its baker can turn the prefab reference into an entity prefab:
public override void Bake(EntitySpawner authoring)
{
if (authoring.m_SpawnData == null || authoring.m_SpawnData.Prefab == null) {
return;
}
var spawner = GetEntity(TransformUsageFlags.Dynamic);
var prefab = GetEntity(authoring.m_SpawnData.Prefab, TransformUsageFlags.Dynamic);
AddComponent(spawner, new EntitySpawnerPrefab { Prefab = prefab });
}
Your ECS system can then instantiate as many copies as it needs. Each copy already contains the baked behavior tree data:
var entities = state.EntityManager.Instantiate(
spawner.Prefab,
spawner.SpawnCount,
Allocator.Temp);
After instantiation, set any per-agent components such as position, movement speed, or team. Trees with Start When Enabled begin automatically. For a tree with deferred start, call StartBakedBehaviorTree for that entity after its setup is complete.
Debug a baked tree
In the Unity Editor, Behavior Designer stores an editor-only link from each baked entity to its authoring graph. Select the running tree in the Behavior Designer window to inspect its execution just like a regular tree. This debugging metadata is removed from player builds.
The Entities Scene sample contains the complete EntitySpawner authoring component and system used by these examples.