I am using Lobby 1.1.0 with the callbacks for Lobby update.
This is the code I am using, I put a print statement in OnLobbyChanged:
private static async Task SubscribeToLobbyChanges()
{
LobbyEventCallbacks callbacks = new LobbyEventCallbacks();
callbacks.LobbyChanged += OnLobbyChanged;
callbacks.KickedFromLobby += OnKickedFromLobby;
callbacks.LobbyEventConnectionStateChanged += OnLobbyEventConnectionStateChanged;
try
{
_lobbyEvents = await Lobbies.Instance.SubscribeToLobbyEventsAsync(JoinedLobby.Id, callbacks);
}
catch (LobbyServiceException ex)
{
switch (ex.Reason)
{
case LobbyExceptionReason.AlreadySubscribedToLobby: Debug.LogWarning($"Already subscribed to lobby[{JoinedLobby.Id}]. We did not need to try and subscribe again. Exception Message: {ex.Message}"); break;
case LobbyExceptionReason.SubscriptionToLobbyLostWhileBusy: Debug.LogError($"Subscription to lobby events was lost while it was busy trying to subscribe. Exception Message: {ex.Message}"); throw;
case LobbyExceptionReason.LobbyEventServiceConnectionError: Debug.LogError($"Failed to connect to lobby events. Exception Message: {ex.Message}"); throw;
default: throw;
}
}
}
private static void OnLobbyChanged(ILobbyChanges changes)
{
if (changes.LobbyDeleted)
{
OnLobbyDisconnect?.Invoke();
OnLobbyDisconnect = null;
RefreshLobbyList();
}
else
{
changes.ApplyToLobby(JoinedLobby);
print(JoinedLobby.Players.Count);
OnLobbyRefresh?.Invoke();
}
}
My flow is this:
Player 1 is creating a lobby. “1” get printed and I can see them in the lobby screen.
Player 2 connects to the lobby. “2” gets printed in Player 1’ editor and I can see both players in the lobby screen.
Player 2 leaves, “1” gets printed in Player 1’s editor and only Player 1 is on the lobby screen.
Player 2 rejoins the same lobby. “1” gets printed in Player 1’s editor. I can see both players on Player 2’s editor, but only Player 1 on Player 1’s editor.
I also tested and only changes.Version.Changed is true, all the other changes return false.
I posted a video below to make this clearer.
73sru7
I fixed the problem by making a request for the lobby in OnLobbyChanged, but that obviously isn’t the intended way to do this.
private async static void OnLobbyChanged(ILobbyChanges changes)
{
if (changes.LobbyDeleted)
{
OnLobbyDisconnect?.Invoke();
OnLobbyDisconnect = null;
RefreshLobbyList();
}
else
{
changes.ApplyToLobby(JoinedLobby);
JoinedLobby = await LobbyService.Instance.GetLobbyAsync(JoinedLobby.Id);
OnLobbyRefresh?.Invoke();
}
}