Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Help with lobby/room

Discussion in 'Multiplayer' started by MidniteOil, Jul 16, 2020.

  1. MidniteOil

    MidniteOil

    Joined:
    Sep 25, 2019
    Posts:
    305
    Greetings, I'm venturing into multiplayer/networked game development using mirror and starting with a simple room/lobby implementation with a custom UI to learn the basics.

    I am using the 2020.1.0b10.3837 version of Unity and grabbed the latest mirror code. I was able to build and run their room and chat examples.

    I copied their NetworkRoomManagerExt and NetworkRoomPlayerExt classes into my project and was able to get it working but with the built-in development UI.

    I am now trying to retrofit it to use my own custom UI.
    upload_2020-7-16_15-15-2.png

    upload_2020-7-16_15-15-52.png

    I've wired the Host Game and Join buttons up to the NetworkRoomManager's StartHost() and StartClient() methods and that all works great.

    The problem arose when I tried to follow the pattern from the Mirror chat example to set the player name.
    I added a Player Name property to the NetworkRoomManagerExt class and wired the OnValueChanged event of my player name input field to it.

    Then, I added the following overrides:

    Code (CSharp):
    1.  
    2.     public override void OnRoomStartServer()
    3.     {
    4.         base.OnRoomStartServer();
    5.         NetworkServer.RegisterHandler<CreatePlayerMessage>(OnCreatePlayer);
    6.     }
    7.  
    8.     public override void OnClientConnect(NetworkConnection conn)
    9.     {
    10.         base.OnRoomClientConnect(conn);
    11.         Debug.Log($"OnClientConnect {conn?.connectionId ?? -1}, {conn?.identity?.hasAuthority}, {conn?.identity?.name ?? "null"}");
    12.  
    13.         // tell the server to create a player with this name
    14.         conn.Send(new CreatePlayerMessage { name = PlayerName });
    15.     }
    Note: I originally tried using OnRoomCoientConnect but that gave me this error:

    So I tried using OnClientConnect() instead.

    This is the result I'm getting:
    upload_2020-7-16_15-25-7.png

    I'm struggling to see how to use my custom UI with the room/lobby code I copied from the sample. The sample hides all the UI/Network interaction and I don't see any good examples of how to replace the built-in developer UI with mine.

    Here's how I've layed out my UI:
    upload_2020-7-16_15-26-31.png

    The Host Button disables the Panel_Login and IPAddress input sections and calls StartHost().
     

    Attached Files:

  2. MidniteOil

    MidniteOil

    Joined:
    Sep 25, 2019
    Posts:
    305
    I've actually got past that error but I am still very confused. I realized the Chat example was instantiating the actual game player in OnClientConnect() which is not what I want. Since this is a lobby I want to instantiate the NetworkRoomPlayer.
    I know the room player is automatically getting instantiated somehow because I see this on the roommanager GUI:
    upload_2020-7-16_16-48-38.png

    In the NetworkRoomManager I see these settings:
    upload_2020-7-16_16-50-50.png

    I want to turn off the default GUI and display my own but I need to know how to intercept the creation of the room players so I can set the player names?

    Can anyone provide an example of this?

    Thanks.
     
  3. Eisnel

    Eisnel

    Joined:
    May 24, 2021
    Posts:
    2
    Did you get or found a way to do this?
    Thanks
     
  4. MidniteOil

    MidniteOil

    Joined:
    Sep 25, 2019
    Posts:
    305