Hi, I subscribed lobby events and trying to send custom lobby data but I can’t receive the data I send through lobby event callbacks. The other lobby members do receive events but I can’t somehow. Shouldn’t I receive the data ?
If you are using 1.1.0-pre.5, this was just changed to not trigger updates for a user’s own changes. If you are using a previous version, then yes, you should still be seeing those callbacks.
@bartj-unity I was also facing the same issue I’m on 1.1.0-pre.5 as well, is this change permanent?
Any news on when the official release is happening for lobby 1.1? I can’t wait to update my game to use events but I need to wait for the official release
That change is expected to be permanent. The reasoning for it was that if you’re making a local change, you can (and should) just apply any logic around your lobby updates immediately instead of relying on, and waiting for, the Lobby service to send you an update event. Timing for the next official release is still TBD.
why make it not trigger the events ? sometime we just want write same logic for both host and member. Just add the config that could be enable it or disable it
+1. This change seems like the wrong API design decision to me.
It’s very likely that multiple different objects will be listening to changes to the lobby. If the event is triggered for both local clients and remote clients then a UI object displaying the value only needs to listen to one changed event. And logically it makes perfect sense that the OnXChanged event should be triggered regardless of who changed X. It’s not called OnXWasChangedByARemoteClient.
With this change we have to add extra logic to trigger the events manually when changed locally, or every time we update data locally we have to also manually update the other objects using that data. It went from one code path to listen to data changes to 2-* code paths, making it more laborious and error prone to work with.
The ability for the local player to receive its own events was changed, but will be enabled by a flag added in the next (unreleased version). The PR has already been merged on master and will be part of Lobby 1.2.0
Lobby 1.2.0 has now been released !
You can configure Lobby to send players their own events like so
(LobbyService.Instance as ILobbyServiceSDKConfiguration).EnableLocalPlayerLobbyEvents(true);
After this configuration is set, the local player will be receiving its own events.
Hi @ArthurAtUnity , I’m using “Multiplayer Services 1.0.2” and I couldn’t find “EnableLocalPlayerLobbyEvents” method.
Actually, my problem is that when I return from the background no events are triggered in the lobby and when I try to exit the game I get a “player not found” error in LobbyService.Instance.RemovePlayerAsync.
Hi @Mj-Kkaya ,
Unfortunately that feature didn’t make it into the Multiplayer SDK yet. In the current version, the local lobby player receives his own events after the Lobby backend responds. Which means if you do not want to react to some events, you need to filter (add conditions, checks, …) in your handling of those events.
Thank you for the report of that issue ! Could you please elaborate on that problem ?
- do you use the “raw” Lobby/Relay/ … or the Sessions ?
- which services are you using (especially if you use Relay on top of Lobby) ?
- which platform (Windows, MacoOS, mobile, console, …) are you testing it on ? in build or in editor ?
- when you mention “from the background” do you mean only unfocused, minimized on Windows or switching application on mobile, having the device in sleeping mode ? (or anything else)
- how do you exit the game ? do you close the window, close the app, or use a button in your UI ?
Hi @ArthurAtUnity , Thanks for your quick response.
1-2 :
I use Lobby without Relay. I don’t use Relay, I use Dedicated Server and Matchmaker but in this condition I haven’t connected to Dedicated server or Matchmaker.
3-4:
I tested on IPhone 18.1.1
I put the game in the background and focus another app.
5: I use button in UI and trigger the “LobbyService.Instance.RemovePlayerAsync(LobbyId, playerId)”
Actually I tried to listen “lobbyEventCallbacks.LobbyEventConnectionStateChanged” event before writing the post and I have got these logs:
If I wait 10 seconds in background then focus the game everything is fine. I also got “lobbyEventCallbacksLobbyChanged” callback.
But if I wait 20 seconds on background then focus the game, there is a problem.
lobbyEventCallbacks.LobbyEventConnectionStateChanged is triggered with “Unsynced”
WebSocketInvalidStateException: WebSocket is not in open state.
at Unity.Services.Wire.Internal.WebSocket.Send (System.Byte[] data) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Services.Wire.Internal.Client.HandleServerPing () [0x00000] in <00000000000000000000000000000000>:0
at Unity.Services.Wire.Internal.Client.OnWebsocketMessage (System.Byte[] payload) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.Tasks.Task.ExecuteWithThreadLocal (System.Threading.Tasks.Task& currentTaskSlot) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.Tasks.Task.ExecuteEntry (System.Boolean bPreventDoubleExecution) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
at Unity.Services.Wire.Internal.Client.WebsocketMessageListener (System.Byte[] data) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_1 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)
lobbyEventCallbacks.LobbyEventConnectionStateChanged is triggered with “Subscribed”
after 12 seconds (I didn’t do anything in this 12 seconds.)
lobbyEventCallbacks.LobbyEventConnectionStateChanged is triggered with “Unsubscribed”
lobbyEventCallbacks.KickedFromLobby is triggered.
Lobby Settings:
Active Lifespan : 15 sc.
Disconnect Removal Time : 10 sc.
Disconnect Host Migration Time : 5 sc.
Hi @ArthurAtUnity ,
Is there any update related this behavior?
Hi @Mj-Kkaya ,
Sorry for the late update. It looks like iOS closes sockets when applications are in the background, so you would need to recreate them when the application comes back to the foreground.
- Call ReconnecToLobbyAsync to tell Lobby that even though the player lost connection (socket closed) they are “still alive” and shouldn’t be removed from the Lobby
- Call a new SubscribeToLobbyEventsAsync to reconnect to the events
You shoud be able to execute it in OnApplicationFocus
or OnApplicationPause
. Here are the respective documentation
Hi @ArthurAtUnity,
I tried the steps and it works fine except for one error log.
When the app comes from the background, no matter how long it has been in the background (it doesn’t matter if it’s 2 seconds or 30 seconds) I always run the “LobbyService.Instance.ReconnectToLobbyAsync(lobbyId)” method and I works well.
But right after the line, I tried to bind to lobby events with the “LobbyService.Instance.SubscribeToLobbyEventsAsync(lobbyID, _lobbyEventCallbacks)” and got an exception.
First:
“lobbyEventCallbacks.LobbyEventConnectionStateChanged” is triggered and it returns LobbyEventConnectionState.Error
after, I got the exception
Unity.Services.Lobbies.LobbyServiceException: You are already subscribed to this lobby, you do not need to subscribe again. ---> Unity.Services.Wire.Internal.AlreadySubscribedException: Already subscribed to $lobby!!!....
Actually, it doesn’t effect the game but, I just want to ask can I prevent this or not?
And is my approach convenient or right?
Hi @Mj-Kkaya ,
Thank you for your report ! Your approach seems correct. I filed a bug on our side, we will investigate and come back to you.