Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Resolved OnPlayerLeft and OnPlayerJoined lobby callback events missing?

Discussion in 'Lobby' started by dre4mer, Dec 4, 2023.

  1. dre4mer

    dre4mer

    Joined:
    May 26, 2016
    Posts:
    7
    I'm trying to use the lobby call back events but it says that specifically PlayerLeft and PlayerJoined don't exist? Is there some other using I am missing? These events are right in the documentation so this seems really odd? The other events don't have an issue. OnLobbyChanged fires. I've installed the Wire 1.2.2 package and the Lobby 1.0.3 Package and I've also added

    UGS_BETA_LOBBY_EVENTS
    and
    UGS_LOBBY_EVENTS

    to scripting symbols


    But if I comment out PlayerLeft and PlayerJoined I get this for both
    'LobbyEventCallbacks' does not contain a definition for 'PlayerLeft' and no accessible extension method 'PlayerLeft'


    Code (CSharp):
    1. using Unity.Services.Lobbies;
    2. using Unity.Services.Lobbies.Models;
    3. using System.Collections.Generic;
    4. using System.Threading.Tasks;
    5. using UnityEngine;
    6. using System.Linq;
    7. using System.Collections;
    8. using Unity.Services.Core;
    9. using Unity.Services.Authentication;
    10. using System;
    11.  

    Code (CSharp):
    1.     var callbacks = new LobbyEventCallbacks();
    2.     callbacks.LobbyChanged += OnLobbyChanged;
    3.     // Optionally add these callbacks if needed
    4.      callbacks.KickedFromLobby += OnKickedFromLobby;
    5.      //callbacks.PlayerLeft += OnPlayerLeft;
    6.      //callbacks.PlayerJoined += OnPlayerJoined;
    7.     callbacks.LobbyEventConnectionStateChanged += OnLobbyEventConnectionStateChanged;
     
  2. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    529
    Lobby has already version 1.1.1 out which has the events you are looking for.
     
  3. dre4mer

    dre4mer

    Joined:
    May 26, 2016
    Posts:
    7
    Thank you for that! I've spent a long time trying to figure out why the heck this wasn't working. : I
     
  4. dre4mer

    dre4mer

    Joined:
    May 26, 2016
    Posts:
    7
    OnPlayer left and Joined do not cause errors now but they also do not seem to fire when a player closes the app even when the player disconnect time is set to 10 seconds in the config for Lobby. :(
     
  5. UnityKristy

    UnityKristy

    Joined:
    Mar 9, 2014
    Posts:
    7
    Make sure to subscribe to the events with SubscribeToLobbyEventsAsync, if you're not already:
    https://docs.unity.com/ugs/en-us/manual/lobby/manual/lobby-events

    If you're also using Relay, you could subscribe to these NetworkManager callbacks along with or instead of the lobby callbacks:

    networkManager.OnClientConnectedCallback
    networkManager.OnClientDisconnectCallback

    This is the script I attach to my NetworkManager:
    https://github.com/Unity-Kristy/Mul...sets/Scripts/Multiplayer/ConnectionHandler.cs
     
    Last edited: Dec 6, 2023
  6. Naggin

    Naggin

    Joined:
    Jun 9, 2019
    Posts:
    7
    It seems like it only works properly if you use the relay <> lobby integration, as soon as the player is disconnected from relay for any reason, they are marked as disconnected on lobby and after 10 seconds they are kicked from the lobby