Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    Dismiss Notice

Network Object not spawning, after re-creating lobby.

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

  1. xIceCubex

    xIceCubex

    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. sorcerer_king

    sorcerer_king

    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. xIceCubex

    xIceCubex

    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..
     
unityunity