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

NetworkID not saved in scene file

Discussion in 'Multiplayer' started by Toadwolf, Sep 17, 2015.

  1. Toadwolf

    Toadwolf

    Joined:
    Sep 4, 2014
    Posts:
    10
    I am working on a prototype for a multiplayer game with a client/server architecture. The game has about 200 floor tiles which change their color depending on the distance of the player to them. This change is managed by the server, which means that each floor tile has its own NetworkIdentity component. Now when I build the game and start the server, then restart the Unity editor and open a client in the edtor, my floor tiles are colored completely randomly.

    After searching for a while I found the simple reason: the network ID of my floor tiles is not stored in the scene file, but assigned anew each time I open the editor. Thus, the number of IDs stays the same, but the relationships between server (built before) and client (started after restarting the editor) are random.

    The easy workaround is, of course, to rebuild my solution when I restart the editor, and the IDs will be in correct order again. But think what happens when I ship this game: each time I release a new version there will be new ID orders. However, players might not update their game at once, so I need my server to know about the orderings of previous versions as well, so that players with older versions of the game can still play.

    Is this observation correct? Is this an intended feature, or wouldn't it be nice to have the network IDs stored in the scene? Did anyone else have this problem before, and what do the Unity devs think about it?

    BTW, I am using Unity 5.1.3. The floor tiles are prefabs but static scene objects.
     
  2. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    470
    Does this lead to a bug you are observing? I believe the server sends the net ids when it spawns objects, so I don't think your clients can get out of sync this way.

    You do need the scene IDs in your server scene to match your client scenes though, I believe.
     
  3. Toadwolf

    Toadwolf

    Joined:
    Sep 4, 2014
    Posts:
    10
    Depends on what you call a bug. I am talking about (static) scene objects which are not spawned by the server. As you wrote, the scene IDs in server and client do not match anymore in that case, so I get random permutations in the coloring of my floor tiles. The work-around is to rebuild the game everytime I reopen the editor. But I always have to keep this in mind.