Syncing Unity's built-in AI over the network

Hello

I have a small “army” of navmesh agents and I’m trying to sync them over the network. They are basically spawned using this code in an OnStartServer method.

GameObject enemy = Instantiate(m_enemyPrefab, transform.position, Quaternion.identity);
NetworkServer.Spawn(enemy);

not really that it matters much

The AI itself has a Nav Mesh Agent component, an enemy script, network identity (set with local player authority) and a Network Transform. When I start a game and join the game with another player and stop them, they tend to just teleport. How can I make them sync correctly over the network so it’s the exact same for every player?

Without more information, here’s a couple of things to check:

  • Make sure you don’t execute the navigation code on the clients also (it only runs on host/server)
  • The networking library has a max amount of bandwidth it can use (it can be configured, but the defaults are sensible for something that should work online). If you have so many units that it can’t send regular updates for all of them, they will stutter.

Can you please provide a link to the docs where it is explained how this limit can be configured and how it works?

In my project, I also need to sync a huge number of server-controlled NPCs across the network. So, it is an important goal to keep bandwidth consumption as low as possible. I don’t use NetworkTransform but a custom script for syncronization of positions and rotations, with some optimization measures. Unfortunately, we currently do not have sufficient tools to measure exact UNET bandwidth consumption yet. Thus, it might be a helpful option to set different bandwidth limits and do some tests to check if/when particular limits are exceeded.

It’s available on the GlobalConfig passed into NetworkTransport.Init