Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Network objects despawning on client when host unloads scene

Discussion in 'Netcode for GameObjects' started by Shack_Man, Aug 24, 2023.

  1. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    373
    What I'm trying to achieve: A host creates a lobby + relay allocation, clients join, the game starts. When the host switches the scene, like going back to the menu, the clients can still continue to play the game.

    What happens however is that all the network objects will despawn in the clients' game scenes. Is there some way to prevent this from happening? Is my only option to use additive scene loading?

    Thanks!
     
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    676
    The objects despawning sounds like the expected default behaviour, isn't the client changing scene as well with the host?
     
  3. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    373

    No, the clients don't change the scene. If I use the NetworkManager.SceneManager to change the scene, then they also change the scene. But I want to achieve the opposite: When the host decides to go back to the menu, the other player's can continue the game. It's a very quick game loop so I just need to keep it around for 30 seconds. But it would be pretty bad to tell the host that they are actually hosting a multiplayer game and if they could please wait a bit for the others....
    Ideally they have no idea they are the host, they just hop into the game, there is no open lobby so they create one and start the network manager as a host and wait for the lobby to fill up.
     
  4. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    676
    I can't see that working, the host is controlling all the network objects in the scene, when they change scenes the network objects will be destroyed. With the scene management being designed to keep scenes and objects in sync, you're going to see some strange behaviour if you try forcing changes in that functionality.

    You can implement your own custom scene management but that's quite involved even without having to worry about a host. I don't know if additive scenes would help you here as I've not used them.