Networking
The recommended approach for Behavior Designer and networking is to have Behavior Designer run on the server. This will ensure the server makes all of the decisions and then sends the clients the results. For example, if the Seek task is running the client should only receive the current position of the agent. With this setup the behavior tree isn’t even aware of the network. This is also true for a client authoritative solution. Only the resulting transform/animation properties should be synced to all other clients. The actual behavior tree does not need to be synchronized across the network.
For a practical example your script would look something like this:
public class BehaviorTreeEnabler : MonoBehaviour { [Tooltip("A reference to the behavior tree.")] public BehaviorTree m_BehaviorTree; private void Awake() { m_BehaviorTree.enabled = IsServer(); } }
The IsServer method depends on your networking implementation but it will ensure the behavior tree is enabled only on the server or the authoritative client in a peer to peer situation. With this setup Behavior Designer can work with any networking implementation.
For Entity clients the EnabledBakedBehaviorTree method should not be called. This will prevent the behavior tree systems from starting on the client and only the server will run the behavior tree. From the Entity Baking page, the spawner script would look something like:
public partial struct EntitySpawnerSystem : ISystem { /// <summary> /// Sets the system requirements. /// </summary> /// <param name="state">The current SystemState.</param> private void OnCreate(ref SystemState state) { state.RequireForUpdate<SpawnData>(); } /// <summary> /// Spawns the entities. /// </summary> /// <param name="state">The current SystemState.</param> private void OnUpdate(ref SystemState state) { state.Enabled = false; var spawner = SystemAPI.ManagedAPI.GetSingleton<SpawnData>(); var entities = state.EntityManager.Instantiate(spawner.Prefab, 100, Allocator.Temp); // Any custom setup for each entity. This can include adding new components, enabling components, setting entity data, etc. // The behavior trees have been baked. if (spawner.IsServer) { // Your networking implementation for determining if the agent is on the server. BehaviorTree.EnableBakedBehaviorTreeSystem(World.DefaultGameObjectInjectionWorld); } } }