Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Third Party [Photon] Best practice to sync the position of NPCs

Discussion in 'Multiplayer' started by goldcloud144, Oct 23, 2021.

  1. goldcloud144

    goldcloud144

    Joined:
    Jun 20, 2020
    Posts:
    9
    Hi, sometimes I have over 40 characters(2 players + enemies) at the same time, that I synced correctly. Now I want to add more than 20 NPCs (as walking people in the scene) whose their position matters (because their role may change dynamically).

    I was wondering if the PhotonTransformView is the right choice? Or maybe there is a better way to do it with less data usage(on the network).
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,082
    In general, you want to stop syncing position updates when characters / NPCs and enemies stop moving.
    Most likely, the code you use to control NPCs and enemies has some flag if the character moved. If it didn't, you could stop sending updates by providing your own, custom IPunObservable code (possibly based on PhotonTransformView).
    There is some more background info in our docs.

    PUN is not great for larger numbers of PhotonViews. Make sure to test what happens when the maximum of characters moves. You may have to apply "Network Culling" with Interest Groups. A prototyping script for that is provided in the PUN 2 package (see CullingHandler.cs).

    We didn't see a good way to fix these limitations without breaking PUN 2 entirely, so we created Fusion as state of the art approach to networking. It would support this number of characters without hitch. I would recommend this for any upcoming project and anything that's a prototype still.
     
    goldcloud144 likes this.