- Home /
Player Prefab on Lobby Managers?
This question is pretty short and straightforward. When I use a regular Network Manager, set a Player Prefab in the Spawn Info, then start a game, the Online scene is loaded and the Player Prefab is spawned.
When I do the same thing with a Network Lobby Manager, the Player Prefab is not spawned.
I am highly confused by this. What is the intended use of the Player Prefab, and why doesn't it get spawned from a Lobby Manager?
I try to do the same thing... According to the documentation, it should work that way, but the playerObjects are not getting spawned and OnLobbyServerSceneLoadedForPlayer is never called. autoCreatePlayer is true
$$anonymous$$y problem was, that i didn't mention to use OnStartLocalPlayer() ins$$anonymous$$d of OnStart() for the LobbyPlayer
$$anonymous$$y problem got fixed too by overriding OnStartLocalPlayer() , not sure why this is working actually, you may try this out.
I am having this exact same issue! OnLobbyServerSceneLoadedForPlayer but OnLobbyClientSceneChanged is! I noticed you both mentioned overriding OnStartLocalPlayer, where? On the lobby player or the game player? I have it overidden on both. However I also have normal Start logic on the player object. This has really been frustrating me. I'm in the process of downloading 5.1.3f in hopes this is some kind of bug that has been addressed.
Answer by darthbator · Sep 01, 2015 at 12:24 AM
So this is what fixed the issue for me
http://forum.unity3d.com/threads/lobbyplayer-to-gameplayer-networklobbymanager.349614/
Take at the above forum post. It looks both OnLobbyServerSceneLoadedForPlayer and OnLobbyServerCreateGamePlayer are called on the LobbyPlayer gameobject AFTER the scene has been transitioned to the "gameplay scene". So if you have not instructed untiy to not Destroy the gameobject on scene transition the above 2 methods will never be called. just DontDestroyOnLoad(gameObject); to the awake method of your LobbyPlayer (or inhereted) gameobject and everything will end up being called as expected.
*Remember Unity appears (does?) to Destroy objects recursively when a scene is loaded. So if you have your lobbyplayer childed to a mortal gameobject it will still be Destroyed in scene change even if you add the above line of code. Remember to unparent the lobbyplayer object before you perform any scene load to make sure it sticks around to do player spawning.
This is what happened for me as well, was using an UI Component for the LobbyPlayer object which I naturally parented to a canvas. The result was it being deleted and thus no spawning of player prefabs.
The lobby player component seems to handle the dontdestroyonload itself, but as you said if it's parented to a mortal object it dies anyway.
Unparenting is so obvious now. I was spawning the lobby player under the lobby manager and having it spawn a UI object to display information, which just created more headaches.
Answer by Wojalin · Jun 30, 2016 at 05:10 PM
Try this and give the guy a cookie! Srsly! He deserves it!
Answer by xristos1989 · Jun 22, 2015 at 03:42 PM
Have you tried adding the a lobby player prefab with the network lobby player component? In lobby manager you must set 2 prefabs.
Answer by omgketchup · Dec 17, 2015 at 04:53 PM
I ran into a similar issue here. In my LobbyPlayer I had an OnLevelWasLoaded call, not marked as an override or anything. I first tried removing all the code in that function, no luck, but removing the function itself let the OnLobbyServerSceneLoadedForPlayer be called.
Answer by Mr-Jun · Oct 04, 2016 at 05:14 AM
The link provided by Wojalin is a great solution.
For those following it, the SetPlayerTypeLobby() function takes a NetworkConnection as an argument. You can pass this argument like so:
LobbyManager.s_Singleton.SetPlayerTeamLobby(connectionToClient, index);
Your answer
Follow this Question
Related Questions
How to fix OnObjSpawn netId: 1 has invalid asset Id when using Lobby example in existing project 0 Answers
Prevent NetworkLobbyManager from changing scenes. 2 Answers
Spawn Prefab inside another Prefab 0 Answers
UNET lazy loading, what does it mean? 1 Answer
OnStart ___ vs OnLobbyStart ___ methods from NetworkManager and NetworkLobbyManager 1 Answer