Search Unity

Scene objects randomly fail to enable

Discussion in 'Multiplayer' started by marcV2g, Jul 12, 2017.

  1. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    On the client scene objects seem to have about a 50% chance of working vs being disabled, anyone know why?

    EDIT: docs
    https://docs.unity3d.com/Manual/UNetSceneObjects.html

    EDIT2:
    does anyone know how scene object netids are generated? How do client and server agree on what game objects to synchronise?
     
    Last edited: Jul 12, 2017
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Short answer - server initializes netId's and sends them to a clients, where they are applied to the objects in the scene.

    Tips:
    0. Make sure all NetworkIdentities are enabled before scene loads. NetworkIdentities manage being enabled/disabled on their own.

    If it's disabled on scene load - it doesn't exists. Because you know. Networking is hard, doing checks are hard and design is a time waste.

    1. Make sure server and client have the same amount of NetworkIdentity components in the scene;
    2. Make sure server and client scripts have the same amount of:
    • SyncVar's
    • Cmd's
    • ClientRpc's
    • SyncLists
    3. Make sure server and client have the same SyncVar structs structure. Otherwise this will cause failure whole scene payload deserialization failure.
    4. Lastly - sometimes UnetWeaver fails, due to Editor Serialization, creating multiple instances of classes, which contain multiple SyncVar's... Yeah rule #2 is now screwed. What to do in such case? Full reimport\Library deletion + rebuild usually helps. If not - you've probably missed something.

    Have fun.
     
  3. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    But how does the client decide what game object gets what netid, is it hierarchy position or a uuid?

    EDIT:

    I forgot to mention it works 100% when server and client are on the same machine, it only fails when run on a remote server.
     
    Last edited: Jul 12, 2017
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    As far as I remember - it's assetId and sceneId that determines it