Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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:
    454
    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:
    6
    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