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

Player prefabs not spawned on clients from custom NetworkLobbyManager

Discussion in 'Multiplayer' started by PHLCollective, Oct 3, 2015.

  1. PHLCollective

    PHLCollective

    Joined:
    Jun 27, 2014
    Posts:
    59
    This has me kind of pulling my hair out, especially because it seems the matchmaking/lobby features of UNet aren't too well documented yet:

    I have a custom NetworkLobbyManager, as well as a custom NetworkLobbyPlayer. Neither of these override or change anything about game player prefab spawning. When I "ready" all the players in the match, it transitions to the game scene correctly for all clients, but the player prefab is being spawned and replacing the lobby player on the host ONLY, not on any of the clients.

    In the host's scene, the lobby player has been replaced by the game player correctly, and the client is indeed connected to the match. However the weird thing is, on the client's scene BOTH the host's and client's lobby player objects are still in the scene, as well as the host's game player object, but that's it. I can't figure out why it won't spawn game player objects properly on the client.

    If anyone has any ideas let me know, thanks!
     
    Mikael-H and Trys10Studios like this.
  2. PHLCollective

    PHLCollective

    Joined:
    Jun 27, 2014
    Posts:
    59
    Some other potentially helpful info: OnLobbyServerSceneLoadedForPlayer is called on the host player, but not the any of the client players
     
    Trys10Studios likes this.
  3. PHLCollective

    PHLCollective

    Joined:
    Jun 27, 2014
    Posts:
    59
    Figured it out. For anyone else who may have a similar problem:
    My lobby manager had references to objects in the lobby scene which got destroyed on the transition to the game scene, leaving their slots as "missing" in the inspector. This was apparently causing the server to be upset and not work properly, so I made the objects DontDestroyOnLoad, and just disabled them at the start of the game scene.
     
    themerphin likes this.
  4. Dinusha_Harankahawa

    Dinusha_Harankahawa

    Joined:
    Jan 25, 2017
    Posts:
    2
    I am new to Unity. I have the same problem. where to put DontDestroyOnLoad? how to disable object? please explain how to do that.
     
  5. Trys10Studios

    Trys10Studios

    Joined:
    Jun 24, 2013
    Posts:
    45
    Dinusha, it's on the Lobby Manager script that you can download in Unity's Asset Store. It is a prefab within that asset called Lobby Manager. DontDestroyOnLoad is a public static function that essentially keeps them (your objects) "alive" (not destroyed) on scene transitions.

    You can call in the start method for each object you want to disable by using gameObject.setactive (false); This basically turns off those objects within that scene when it loads. This way you can turn it on and off as you need within that scene.

    https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
     
  6. haywirephoenix

    haywirephoenix

    Joined:
    May 17, 2017
    Posts:
    101
    You just saved my life