Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Third Party How do I sync objects for all clients? [Photon Pun]

Discussion in 'Multiplayer' started by jlorenzi, Jan 5, 2024.

  1. jlorenzi


    May 2, 2021
    If I have something like an enemy in my scene, and 2 players join the same room, wouldn't that create 2 separate instances of the enemy for the 2 players? This is a problem because if one player joins a bit later than the other player, the enemy for the player who joined late will still be at it's origin position and won't be updated and then you'll have the enemy be out of sync for the two players. How do I fix this?
  2. tobiass


    Apr 7, 2009
    You need to make sure only one client in the room instantiates the enemies. E.g. the Master Client can do this. When the current Master Client leaves before doing this, there is a callback that the Master Client switched. Use this as fallback and create the enemies if they are not yet there.

    Instantiation is not updated, so all new characters / enemies are placed where you instantiated them. You can add a script to hide them until a first "update" arrived.
    jlorenzi likes this.