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

Sync objects in active game after a client reconnects

Discussion in 'Multiplayer' started by thedrhax14, Aug 15, 2018.

  1. thedrhax14

    thedrhax14

    Joined:
    Aug 7, 2014
    Posts:
    38
    Hi,

    I have a question: How to sync objects or update their transform or active state when a client reconnects to a server?

    For example, Admin player created server, then waited for another player to connect. Both players have "spawned" some GameObjects. These GameObjects are always active in the game scene and have NetworkIdentity component on them. They also have NetworkTransform component to sync position and rotation. So, when a player is trying to "spawn" something, he or she just moves parent object and activate its child. Now, because of network issues, client disconnects and decides to reconnect again. After reconnection these objects are in the same place and state on the server, but client doesn't have this update. For a client it seems they have never been "spawned". How to sync these objects when a client reconnects?

    UPDATE: 16 Aug 12:42

    I just noticed that these objects are moved to the same position where server's ones are, but states of its children are false. Is there way to sync this too? I know that children can be active by default, but it is done for optimization purposes.
     
    Last edited: Aug 16, 2018
  2. thesupersoup

    thesupersoup

    Joined:
    Nov 27, 2017
    Posts:
    70
    I had tons of trouble using NetworkTransform; I ended up going with SmoothSync for my project.
    It handles clients leaving and returning flawlessly, with regard to synchronized position and rotation.
    SmoothSync also supports syncing children objects with additional SmoothSync scripts on the parent object. If there's data state related info you're trying to sync, though; you might have to do that via SyncVars or your own personal solution. I drive NPC animation with a combination of SyncVars for state info like isDead, isAsleep, isAttacking, etc. and a non-synchronized char variable which represents the active animation that the server pushes to the NPCs, but can be overridden by certain local states like being dead.
     
  3. thedrhax14

    thedrhax14

    Joined:
    Aug 7, 2014
    Posts:
    38
    I am quite happy with NetworkTransform.
    I didn't mean data state. I meant their active state in the hierarchy.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If you're changing the active state of child objects after the object has been spawned, you'll probably need to sync that manually when new players connect. I might put a targetrpc on any object I do this to that will send the active status of any of its child objects, and then call this on every object after the new player gets in. Might be a bad idea if we're talking about a lot of objects though.
     
  5. thedrhax14

    thedrhax14

    Joined:
    Aug 7, 2014
    Posts:
    38
    This is actually a good idea, but I decided that the problem is not so critical to solve it