Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Efficient Network Synchronization of multiple NPC AI Characters (25+)

Discussion in 'Multiplayer' started by moco2k, Aug 27, 2015.

  1. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    Hey everyone,

    I'm working on an FPS game that involves up to 5 players and a lot of AI controlled monsters which all need to be synched across the network (similar to the game Killing Floor). For now, let's say I set the maximum count of concurrently active monsters to 25. I guess this is already a quite big number so I need an efficient way to synchronize these monsters across the network.

    Right now, I do all the navAgent pathfinding stuff for the monsters exclusively on the server and send regular updates of the monsters positions and rotations using a NetworkTransform for each monster. I'm afraid this consumes a lot of bandwidth. I am not sure if my calculation is completely right, but when considering 25 monsters, 15 updates/sec, 36 Bytes for a transform, and 5 clients, that seems to be: 25*15*36*5 = 67.5 KBytes/s = 552,96 KBits/s that need to be send by the server for all monsters each second? I am afraid this might be too much.

    Alternatively, I can think of just using less frequent updates in order to save bandwidth. I guess this would be more dependent on movement interpolation (btw, are there any good docs available on using interpolation with NetworkTransform yet?).

    Or, as another approach, maybe the path finding could even be done on the clients. However, I am afraid that this might not necessarily be deterministic and in sync across all clients at every time because I presume that small position differences could possibly lead to different path finding results.

    Well, any help, shared experiences, approaches and best practices on this issue are very much appreciated.

    Which would be an efficient way respectively a good tradeoff solution to approach this issue?

    Thanks & cheers
    moco
     
    Last edited: Sep 3, 2015
  2. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    *Bump* I still hope someone has some experiences with this.

    In fact, it does not necessarily need to be UNet solution. I am actually interested in a good general approach / best practice to implement network synchronization of high numbers of NPCs.
     
  3. Firoball

    Firoball

    Joined:
    Aug 6, 2015
    Posts:
    60
    If it's not very complex movement you schould easily be able to reduce the data size required for a transform.
    X/Y/Z position, Y Euler angle. That's 16 bytes per transform (unless you also need scaling).
    Depending on required resolution you can further compress using fixpoint representation.
    Also the NetworkTransform offers some static compression methods.

    Next you should make use of the NetworkProximityChecker which allows selective updates for visible-only (configurable distance to player) objects on each client.
    I haven't used that one yet, though.
     
    moco2k likes this.
  4. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    Ah, that will help, thanks a lot! :)
     
  5. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    221
    Get an acceptable solution?
     
  6. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    I think so. Before sending data to clients, I use SlimMath to compress all position floats to ushorts. In addition, I convert the rotation y value to a byte which provides enough accuracy for my needs. This way the synced data for each character is only 7 bytes. Of course, data is only synced if there are any significant changes.

    I've not tried the NetworkProximityChecker so far but I have it on my todo list.
     
    Last edited: Jan 9, 2018
  7. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    221
    Have you ever run into any problems with endianness with the byte conversion?
     
  8. Deleted User

    Deleted User

    Guest

  9. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    221