Search Unity

Resolved How do I get other player's id as a host?

Discussion in 'Lobby' started by rodrigo_unity487, Sep 27, 2022.

  1. rodrigo_unity487

    rodrigo_unity487

    Joined:
    Feb 23, 2022
    Posts:
    8
    Hi!

    Ok I know this is probably an easy one but I'm at a loss, I've spent the last hour searching for a way to retrieve other player's ids as a host. I need them so that I can kick players from the lobby as a host. Where can I get them from? Thank you in advance...
     
  2. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    487
    You can use the following code to do this:

    Code (CSharp):
    1. // Get the lobby
    2. var lobby = await LobbyService.Instance.GetLobbyAsync("lobbyID");
    3.  
    4. // Get a player
    5. var player = lobby.Players[0];
    6.  
    7. // Remove the player
    8. await LobbyService.Instance.RemovePlayerAsync("lobbyID", player.id);
    Not every method (best example is the GetLobbyAsync(string lobbyId) method) is documented, which is very annoying. Best guess is to always take a look at the service class and its method. You can find more information there when reading the source code.
     
    rodrigo_unity487 and bartj-unity like this.
  3. bartj-unity

    bartj-unity

    Unity Technologies

    Joined:
    Sep 9, 2021
    Posts:
    26
    Could you point out where you were looking before? We can try to make that documentation easier to find.

    For reference, you can find the high-level GetLobbyAsync documentation here. From there, you could look at the Lobby model and Player model documentation in order to see that the player IDs will be returned there. It also might have been easier to just use our API documentation in this case.
     
  4. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    487
    My bad, I didn't look at the interfaces all the way down below, I was looking at LobbyService and not ILobbyService.
     
    bartj-unity likes this.