Search Unity

How to spawn different game player prefab with gui lobby manager?

Discussion in 'Connected Games' started by dworm, Jun 18, 2015.

  1. dworm

    dworm

    Joined:
    Jun 17, 2015
    Posts:
    71
    Is it possible if you have different kind of players to decide which one to spawn?
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    The NetworkLobbyManager has virtuals you can override:

    Code (CSharp):
    1.         public virtual GameObject OnLobbyServerCreateLobbyPlayer(NetworkConnection conn, short playerControllerId)
    2.         {
    3.             return null;
    4.         }
    5.  
    6.         public virtual GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
    7.         {
    8.             return null;
    9.         }
     
    DigohD likes this.
  3. DigohD

    DigohD

    Joined:
    Mar 15, 2015
    Posts:
    1
    Hi!

    I want to use this method in order to add custom made lobby entries in a UI. However, the entries do not show up on the connected clients, only to the host. Seanr, do you know what might be wrong? This is my code:

    Code (CSharp):
    1. public override GameObject OnLobbyServerCreateLobbyPlayer(NetworkConnection conn, short playerControlID){
    2.         GameObject newLobbyPlayer = (GameObject) Instantiate(lobbyPlayer, lobbyPlayer.transform.position, Quaternion.identity);
    3.         newLobbyPlayer.transform.SetParent(entryPos, false);
    4.         NetworkServer.Spawn(newLobbyPlayer);
    5.         return null;
    6.     }
    Edit: It would be helpful if you have any idea of what the default code would look like as well :)
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    in those functions you should create an object and return it. you are returning null.
     
  5. Ahkilleux

    Ahkilleux

    Joined:
    Mar 8, 2014
    Posts:
    2

    Also, I'm pretty sure your parent relationship will not replicate to clients. So if you, like me, are spawning ui elements you intend to replicate to the client. They will not have a parent canvas on the other side.

    EDIT: Also, do not spawn in OnLobbyServerCreateLobbyPlayer. That method is intended to instantiate. Spawning there will cause the networklobbyplayer to enter lobby without it's slot property set correctly and possibly have a lot of other problems.
     
    Last edited: Aug 23, 2015
  6. Eiseno

    Eiseno

    Joined:
    Nov 1, 2015
    Posts:
    83
    How can i make this with user can select their prefab.I think i need varible for this.But i cant figure how can i do this.
     
unityunity