Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

LOBBYMANAGER: Setting the spawn prefab index, prior to OnLobbyServerCreateGamePlayer

Discussion in 'Connected Games' started by mcbauer, May 5, 2018.

  1. mcbauer


    Oct 10, 2015
    I have a found a couple of topics on this, but no one is addressing my particular issue.

    Essentially, I have the system working pretty well, I have updated the Network Lobby from the asset store, to include my buttons for selecting the player character. I set the prefab index from those buttons in this script which is applied to the LobbyManager object:

    Code (CSharp):
    1. public class NetworkLobbyHook : LobbyHook
    2. {
    3.     public short p_index;
    5.     public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer, GameObject gamePlayer)
    6.     {
    7.         LobbyManager nlm = NetworkLobbyManager.singleton.GetComponent<LobbyManager> ();
    8.         Debug.Log ("Before LobbyManager playerPrefabIndex = " + nlm.playerPrefabIndex);
    9.         nlm.playerPrefabIndex = p_index;
    10.         Debug.Log ("After LobbyManager playerPrefabIndex = " + nlm.playerPrefabIndex);
    12.     }
    14.     public void chooseRedBoy ()    {p_index = 2;}
    15.     public void chooseRedGirl (){p_index = 3;}
    16.     public void chooseBlueBoy (){p_index = 4;}
    17.     public void chooseBlueGirl (){p_index = 5;}
    18.     public void chooseYellowBoy (){    p_index = 6;}
    19.     public void chooseYellowGirl (){p_index = 7;}
    21. }

    and in LobbyManager:

    Code (CSharp):
    2. public short playerPrefabIndex;
    3. public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
    4.         {
    5.             Debug.Log ("CreateGamePLayer = " + playerPrefabIndex);
    6.             GameObject _temp = (GameObject)GameObject.Instantiate(spawnPrefabs[playerPrefabIndex], startPositions[conn.connectionId].position, Quaternion.identity);
    7.             NetworkServer.AddPlayerForConnection(conn, _temp, playerControllerId);
    8.             return _temp;
    9.         }
    My issue is that the setting of my prefab index happens after the lobby has created the game player. My output log looks like this:

    CreateGamePLayer = 2 (default value)
    Before LobbyManager playerPrefabIndex = 2
    After LobbyManager playerPrefabIndex = 7 ( value set from the button)

    How can I set the index prior to the server creating the game player?
  2. mcbauer


    Oct 10, 2015
    Is there a suggested approach to do this? I'm fine if how I'm going about this is wrong, I'm really in limbo until I can get past this.