Search Unity

Network Object not spawning, after re-creating lobby.

Discussion in 'Netcode for GameObjects' started by NicolaiDMadsen, Sep 5, 2022.

  1. NicolaiDMadsen

    NicolaiDMadsen

    Joined:
    Nov 20, 2014
    Posts:
    2
    Hey guys! I have a problem with Netcode, and i figured some of you might have any ideas on how to fix it.

    I am working with relay and lobby, and creating the lobby and playing the game works flawlessly.

    Before.png .

    The problem arises when the player either leaves the games, or it ends. The player is able to create and join a new lobby, but my lobby manager does not get spawned on the network the second time around. This results in the player panels not spawning, nor does the ready up button appear.

    After.png

    Spawn button.png

    If i manually spawn the lobby manager using the button from the inspector, every thing appears as it should. Do you have any idea why my manager is not getting spawned after reloading my lobby scene?

    Here is the console log..

    Console log.png

    Thanks in advance!
     
  2. pdeschain-unity

    pdeschain-unity

    Unity Technologies

    Joined:
    Sep 21, 2018
    Posts:
    1
    It seems like your LobbyOrchestrator object gets destroyed and not recreated when you do a new play-through. Are you certain that it isn't accidentally destroyed and not recreated in user code? I would double-check around the completion logic to see if LobbyOrchestrator gets removed when you actually want it to live on, or to recreate it in code if it needs to be destroyed for some reason.

    The way we prevent this kind of issue in Boss Room sample is by having a well-defined application startup and state flow, where we very explicitly (by using dependency injection) keep track of our important services (such as lobby). We also reload the game scene between playthroughs, so all the necessary state is properly cleaned up and restored.
     
    Last edited: Sep 6, 2022
  3. NicolaiDMadsen

    NicolaiDMadsen

    Joined:
    Nov 20, 2014
    Posts:
    2
    The LobbyOrchestrator gets destroyed upon loading the game scene, and re-created when loading back to the lobby. Is there a better way to do this?

    The problem is not that it doesn't get re-created. It seems as if the the "OnNetworkSpawn" on the Orchestrator is never called, since the object is never spawned upon the network. (see picture 3)

    I found a work-around, which only works locally. In an update function, i check if the networkobject isn't spawned, and if i am in a lobby - if so then i manually spawn the object. This is however not a solution, as it creates a lot of errors upon the client loading the second time..