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

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,062
    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.