Search Unity

Resolved SubscribeToLobbyEventsAsync (Not receiving callbacks)

Discussion in 'Lobby' started by FrowsyFrog, May 12, 2023.

  1. FrowsyFrog

    FrowsyFrog

    Joined:
    Jan 19, 2021
    Posts:
    2
    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:

    Code (CSharp):
    1.     LobbyEventCallbacks _callbacks = new LobbyEventCallbacks();
    2.     private async void SubscribeToCalls(string _lobbyId)
    3.     {
    4.         // SUBSCRIBE TO CALLS
    5.         _callbacks.LobbyChanged += OnRoomPropertiesUpdate;
    6.         try
    7.         {
    8.             _lobbyEvents = await Lobbies.Instance.SubscribeToLobbyEventsAsync(_lobbyId, _callbacks);
    9.             Debug.Log(_lobbyEvents);
    10.             Debug.Log($"Subscribe... {_lobbyId}");
    11.         }
    12.         catch (LobbyServiceException e)
    13.         {
    14.             Debug.Log(e);
    15.         }
    16.     }

    Code (CSharp):
    1.     private void OnRoomPropertiesUpdate(ILobbyChanges changes)
    2.     {
    3.         Debug.Log("was called!!!");
    4.     }
     
  2. FrowsyFrog

    FrowsyFrog

    Joined:
    Jan 19, 2021
    Posts:
    2
    Ok! I fixed it! I just needed to update my Lobby version
     
  3. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    179
    Well, would you change the title's status from "Bug" to "Resolved"
     
  4. Shiiigear

    Shiiigear

    Joined:
    Oct 7, 2020
    Posts:
    5
    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 !
     
  5. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    179
    Have you ever used the Package Manager to install/update any package?
     
  6. Shiiigear

    Shiiigear

    Joined:
    Oct 7, 2020
    Posts:
    5
    Of course :D
    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.
     
  7. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    179
    What is your issue exactly?
    Could you share any script and log? It will be more specific.
     
  8. Shiiigear

    Shiiigear

    Joined:
    Oct 7, 2020
    Posts:
    5
    That's what I got to subscribe events.
    Code (CSharp):
    1. private static async Task SubcribeToLobbyEvent()
    2.     {
    3.         LobbyEventCallbacks callbacks = new LobbyEventCallbacks();
    4.         callbacks.PlayerDataChanged += ctx => OnDataUpdate();
    5.         callbacks.LobbyChanged += OnLobbyChanged;
    6.         callbacks.KickedFromLobby += OnKickedFromLobby;
    7.         callbacks.LobbyEventConnectionStateChanged += OnLobbyEventConnectionStateChanged;
    8.         try
    9.         {
    10.             await LobbyService.Instance.SubscribeToLobbyEventsAsync(currentLobby.Id, callbacks);
    11.         }
    12.         catch (LobbyServiceException ex)
    13.         {
    14.             switch (ex.Reason)
    15.             {
    16.                 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;
    17.                 case LobbyExceptionReason.SubscriptionToLobbyLostWhileBusy: Debug.LogError($"Subscription to lobby events was lost while it was busy trying to subscribe. Exception Message: {ex.Message}"); throw;
    18.                 case LobbyExceptionReason.LobbyEventServiceConnectionError: Debug.LogError($"Failed to connect to lobby events. Exception Message: {ex.Message}"); throw;
    19.                 default: throw;
    20.             }
    21.         }
    22.     }
    Then I update player data with that method using local saved data:
    Code (CSharp):
    1.     public static async Task<Lobby> UpdatePlayerPublicData()
    2.     {
    3.         if (currentLobby == null) return null;
    4.  
    5.         try
    6.         {
    7.             UpdatePlayerOptions options = new UpdatePlayerOptions();
    8.             options.Data = new Dictionary<string, PlayerDataObject>()
    9.             {
    10.                 {
    11.                     "PlayerName", new PlayerDataObject(
    12.                         visibility: PlayerDataObject.VisibilityOptions.Public,
    13.                         value: CloudSaveData.playerPublicData.name)
    14.                 },
    15.                 {
    16.                     "PlayerProfilePic", new PlayerDataObject(
    17.                         visibility: PlayerDataObject.VisibilityOptions.Public,
    18.                         value: CloudSaveData.playerPublicData.profilePicId.ToString())
    19.                 }
    20.             };
    21.             currentLobby = await LobbyService.Instance.UpdatePlayerAsync(currentLobby.Id, AuthenticationService.Instance.PlayerId, options);
    22.             return currentLobby;
    23.         }
    24.         catch (LobbyServiceException e)
    25.         {
    26.             Debug.Log(e);
    27.             return null;
    28.         }
    29.     }
    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
     
  9. Shiiigear

    Shiiigear

    Joined:
    Oct 7, 2020
    Posts:
    5
    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 :D

    So for the conclusion, callbacks are broken again with version 1.1.0-pre5 :(
     
  10. bartj-unity

    bartj-unity

    Unity Technologies

    Joined:
    Sep 9, 2021
    Posts:
    26
    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?)
     
    Shiiigear likes this.
  11. Shiiigear

    Shiiigear

    Joined:
    Oct 7, 2020
    Posts:
    5
    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 :)