Search Unity

UNET Sync GameObject Active state, Players object enabled or disabled

Discussion in 'UNet' started by Hardstop, Jan 11, 2017.

  1. Hardstop

    Hardstop

    Joined:
    Aug 31, 2013
    Posts:
    23
    Hi
    I'm thinking how to solve a synchronization issue on unet networking solution.
    My player has certain items attached to its bones and objects, now i sync them between clients once attached, but once a player disconnects and reconnects, the enabled or disabled state doesn't stay synced and from reading unet manual, it doesn't have to.

    So now im trying to make a state synchronization system, still trying to find help and maybe experience from people, how to solve and which way.

    Any advice, experimental solutions/code is greatly appreciated.

    I know that there's basically two options i know about how to solve them, synclist and rpc sync straight from the gameobject, but still keeping my eye open for a easier or a more effective solution.
     
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    You won't want to use RPC's for 2 reasons
    1: There are currently bugs (sometimes RPC's aren't received)
    2: When a player reconnects the RPC isn't called and you have no idea if something is enabled/disabled.

    You will want to use Custom UNET Serialization/SyncVars/SyncList because when a player reconnects they will automatically get the latest value during OnDeserialize (occurs after Awake, but before Start). Few things to note:
    1: SyncVars/SyncList would work fine for this in most cases. But they are currently buggy and can be desynchronized and hooks/callbacks can fail.
    2: You can use custom serialization to avoid UNET bugs with SyncVars/SyncLists. It's more work, but in the long run it will be more robust (at least until they fix UNET bugs).
     
  3. Hardstop

    Hardstop

    Joined:
    Aug 31, 2013
    Posts:
    23
    Thank for the advice, didn't know it was bugged. I'm currently on the verge of finishing the SyncStructList example. Going to try this out, if it doesn't work i guess i will have to create my custom serialization method. If i get it working, i'm going to provide an example script here for other stuck with the same problem :p
     
  4. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    OK. SyncList struct should also work. But be careful it can bug out (desync or fail to call hooks) due to lateConnecting players or scene changes.
     
  5. Hardstop

    Hardstop

    Joined:
    Aug 31, 2013
    Posts:
    23
    Yeah, i got the Synclist struct kind of working, but still in progess. I made some test cases and tried them out, found that, if a host connects and starts the server, enables his gameobject, it is synced and when client later after enabling connects, it is synced with client aswell, but once the client disconnects and reconnects then the gameobject is back to disabled state. I dont know if it's related to that bug, perhaps code missing some piece or i'm just not reseting currently since my manual overrides of network functions are not yet integrated from old system.
     
  6. stjernerlever

    stjernerlever

    Joined:
    Oct 25, 2015
    Posts:
    10
    Ever found a good way?

    I have a player prefab that has multiple models to choose from. A player can select a model by clicking a button. This activates a model by ethan.setActive(true); With Rpc and Cmd this is synced to other clients, but if a client connects after the change, they don't see it. [SyncVar] cannot be used, because the model is a GameObject.
     
  7. LaurNTU

    LaurNTU

    Joined:
    Aug 15, 2019
    Posts:
    17