Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Network Manager Client in Scene A (lobby) connecting to Server in Scene B (ingame)

Discussion in 'Multiplayer' started by EnlightenedOne, Jan 21, 2017.

  1. EnlightenedOne

    EnlightenedOne

    Joined:
    Jun 17, 2015
    Posts:
    14
    Hi All,

    I am on Unity 5.5.0f3 and I am trying to make a server which can support a lobby scene and an ingame scene with a twist that clients can join the game during the ingame scene. My real goal is a solid understanding of UNET and its pipeline so I can confidently roll a networked procedural open world... baby steps first.

    I took the Tanks Network demo and tweaked the NetworkLobby (and NetworkPlayer) to so that players can join midgame, I also changed the GameManager so that all players connect ad-hoc and the round never ends.

    Now when I start a server and have the local player jump into the game everything is OK. When I connect on a second unity instance the game scene is loaded but the client throws a CRC warning, presumably because the NetworkManagers are expecting to meet on the same scene:
    "
    Network configuration mismatch detected. The number of networked scripts on the client does not match the number of networked scripts on the server. This could be caused by lazy loading of scripts on the client. This warning can be disabled by the checkbox in NetworkManager Script CRC Check.
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
    "

    Immediately after the CRC warning I get these errors:
    "
    Spawn scene object not found for 1
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
    Spawn scene object not found for 2
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
    "

    Presumably the errors are due to desynced scene networkIds. The server can see both player 1 and 2 as tanks, the client can see player 2's tank (their own) but appears to have spawned the lobby player controller object for player 1 and 2 (especially odd for player 1 given that their player controller was replaced before player 2 connected). After the errors both players can fire rounds from their tanks and tank 2's driving is synchronised.

    If using scenes and Network Manager together is constrained by them needing to begin their conversation in one predetermined scene I guess I need to create the NetworkManager in the ingameScene on server and use prefabs to overlay the lobby in that scene based on replacing player controllers between rounds.

    If anyone has successfully solved this sync problem or has any hints or advice (including not to use multiple scenes because of x) I am keen to hear it.

    Thanks,
    EnlightenedOne
     
    Last edited: Jan 21, 2017
  2. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    We started using the NetworkLobby stuff, but went back to "just" networkManager for this reason. Our lobby is simply a menu UI that we display on top of the "real" game, so ppl can join at any time, and avoid the multi-scene dance of how NetworkLobby wanted to work. There is only offline scene and, once joined to a network game, the online scene (the map you are playing in). This worked for how our game works.

    Good Luck!
     
  3. EnlightenedOne

    EnlightenedOne

    Joined:
    Jun 17, 2015
    Posts:
    14
    Hi Jos-Yule,

    It sounds like you are using my fallback position, thank you for keeping me informed that I am not the only one. I had read the NetworkLobby classes from bitbucket and rolled a variation extending NetworkManager to try my rejigged behaviour (if Unity stopped posting the source UNET would be almost unapproachable).

    I believe I will take that path but I am curious if there is an official party line on this stuff, for now I have to assume the library does not support it.

    Thanks,
    EnlightenedOne
     
  4. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    I have had the same issue and do not know how to fix. I think it has something to do with the order UNET serializes & scene changes when connecting... it tries to deserialize the objects on the client before the client has loaded that scene... so those objects don't exist yet on the client (I think).

    The only solution I have found is that during the connection process to have all players in a scene with no networked objects. Once everybody is connected then a new scene can be loaded.

    I have also noticed that the issue only occurs with networked scene objects, not networked spawned objects.
     
  5. EnlightenedOne

    EnlightenedOne

    Joined:
    Jun 17, 2015
    Posts:
    14
    Thanks for the update, I will definitely stick to the single scene workaround for now just to keep things simple as that in theory should fly.

    Next stop for me is going to be building a solid client/server procedural world manager full of tiled chunks, what are the odds I will make it as far as Object Visibility before my next problem? A dev can dream :)