Well, what I’m trying to do is to subscribe to the lobby events when a player joins a room. However, the _lobbyEvents variable is still null, and OnRoomPropertiesUpdate is not being called when I update the lobby. I really need help with this as I’m new to using the Lobby Service.
Here’s the code snippet I’m currently using:
LobbyEventCallbacks _callbacks = new LobbyEventCallbacks();
private async void SubscribeToCalls(string _lobbyId)
{
// SUBSCRIBE TO CALLS
_callbacks.LobbyChanged += OnRoomPropertiesUpdate;
try
{
_lobbyEvents = await Lobbies.Instance.SubscribeToLobbyEventsAsync(_lobbyId, _callbacks);
Debug.Log(_lobbyEvents);
Debug.Log($"Subscribe... {_lobbyId}");
}
catch (LobbyServiceException e)
{
Debug.Log(e);
}
}
private void OnRoomPropertiesUpdate(ILobbyChanges changes)
{
Debug.Log("was called!!!");
}
Ok! I fixed it! I just needed to update my Lobby version
Well, would you change the title’s status from “Bug” to “Resolved”
Hi, I am facing the same issue but I can’t find what you meant by “update my lobby version”. Can you please provide some updated code or more details on the fix? Thanks !
Have you ever used the Package Manager to install/update any package?
Of course
I am on the last version of the package (1.1.0-pre5) and it’s still broken.
I was confused about the “Version” variable in Lobby class.
What is your issue exactly?
Could you share any script and log? It will be more specific.
That’s what I got to subscribe events.
private static async Task SubcribeToLobbyEvent()
{
LobbyEventCallbacks callbacks = new LobbyEventCallbacks();
callbacks.PlayerDataChanged += ctx => OnDataUpdate();
callbacks.LobbyChanged += OnLobbyChanged;
callbacks.KickedFromLobby += OnKickedFromLobby;
callbacks.LobbyEventConnectionStateChanged += OnLobbyEventConnectionStateChanged;
try
{
await LobbyService.Instance.SubscribeToLobbyEventsAsync(currentLobby.Id, callbacks);
}
catch (LobbyServiceException ex)
{
switch (ex.Reason)
{
case LobbyExceptionReason.AlreadySubscribedToLobby: Debug.LogWarning($"Already subscribed to lobby[{currentLobby.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;
}
}
}
Then I update player data with that method using local saved data:
public static async Task<Lobby> UpdatePlayerPublicData()
{
if (currentLobby == null) return null;
try
{
UpdatePlayerOptions options = new UpdatePlayerOptions();
options.Data = new Dictionary<string, PlayerDataObject>()
{
{
"PlayerName", new PlayerDataObject(
visibility: PlayerDataObject.VisibilityOptions.Public,
value: CloudSaveData.playerPublicData.name)
},
{
"PlayerProfilePic", new PlayerDataObject(
visibility: PlayerDataObject.VisibilityOptions.Public,
value: CloudSaveData.playerPublicData.profilePicId.ToString())
}
};
currentLobby = await LobbyService.Instance.UpdatePlayerAsync(currentLobby.Id, AuthenticationService.Instance.PlayerId, options);
return currentLobby;
}
catch (LobbyServiceException e)
{
Debug.Log(e);
return null;
}
}
After the data update, none of the callback is called as I was expecting PlayerDataChanged and LobbyChanged to get fired.
I really take care of OnLobbyEventConnectionStateChanged callback value received is “Subscribed” before expecting a callback, but none of the data modification will triggers the callabcks anyway.
More infos: I don’t get any exeptions during whole process
Ok I finally found a solution.
I was looking on the samples and I found out that all samples worked with 1.1.0-pre4 package version. I switched to that and it worked without any modification, my code’ is working
So for the conclusion, callbacks are broken again with version 1.1.0-pre5
Have a look at this forum post (I’m guessing you were making updates and looking for callbacks to be triggered using the same player?)
1 Like
That’s exactly my problem. Thanks for the explanation!
I really don’t like this change but I will use it anyway. I will manually call my callback method with changes done on local player