Search Unity

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

Question Unity Multiplay Service gets stuck in OnAllocate at GetPayloadAllocation

Discussion in 'Matchmaker' started by Lemior, Jun 15, 2023.

  1. Lemior

    Lemior

    Joined:
    Nov 12, 2020
    Posts:
    15
    Hello,

    im currently having a problem when using netcode for gameobjects and matchmaker. A few weeks ago everything was working fine and i could connect to the server. But suddenly it stopped working. After investigating i found the error. In the OnAllocate function
    Code (CSharp):
    1. m_MultiplayEventCallbacks = new MultiplayEventCallbacks();
    2. m_MultiplayEventCallbacks.Allocate += OnAllocate;
    i try to get the result of the allocation with
    Code (CSharp):
    1. string payload = MultiplayService.Instance.GetPayloadAllocationAsPlainText().Result;
    I added a debug.log before and after this statement. The server reaches the first debug.log but never the second. So that means it is stuck at this statement. After that i added a for loop that logs the status of the task

    Code (CSharp):
    1. for (int i = 0; i < 1000; i++)
    2. {
    3.     Debug.Log(test.Status);
    4.     System.Threading.Thread.Sleep(100);
    5.     if (test.IsCompleted)
    6.     {
    7.         payload = test.Result;
    8.         i = 100000;
    9.     }
    10. }
    11.  
    It prints: WaitingForActivation

    I tried to rearrange the order of the initialization options but it did not work. After removing this statement everything went on fine and crashed later, because the payload was empty which is perfectly fine, because my game needs this information.

    I do the following things:
    Code (CSharp):
    1. if (UnityServices.State == ServicesInitializationState.Uninitialized)
    2.     await UnityServices.InitializeAsync();
    3.  
    4. m_MultiplayEventCallbacks = new MultiplayEventCallbacks();
    5. m_MultiplayEventCallbacks.Allocate += OnAllocate;
    6. m_MultiplayEventCallbacks.Deallocate += OnDeallocate;
    7. m_MultiplayEventCallbacks.Error += OnError;
    8. m_MultiplayEventCallbacks.SubscriptionStateChanged += OnSubscriptionStateChanged;
    9. m_ServerEvents = await MultiplayService.Instance.SubscribeToServerEventsAsync(m_MultiplayEventCallbacks);
    10.  
    11. NetworkManager.Singleton.NetworkConfig.ConnectionApproval = true;
    12. NetworkManager.Singleton.ConnectionApprovalCallback += OnConnectionApprovalCallback;
    13. NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnectCallback;
    14. NetworkManager.Singleton.OnClientDisconnectCallback += OnClientDisconnectCallback;
    15.  
    16. m_ServerQueryHandler = await MultiplayService.Instance.StartServerQueryHandlerAsync(UnityNetworkData.DEFAULT_MAX_PLAYERS, UnityNetworkData.DEFAULT_SERVER_NAME, UnityNetworkData.DEFAULT_GAME_TYPE, UnityNetworkData.DEFAULT_BUILD_ID, UnityNetworkData.DEFAULT_MAP);
    17.  
    18. ServerConfig serverConfig = MultiplayService.Instance.ServerConfig;
    19. if (serverConfig.AllocationId == "") return;
    20.      NetworkManager.Singleton.GetComponent<Unity.Netcode.Transports.UTP.UnityTransport>().SetConnectionData("0.0.0.0", serverConfig.Port, "0.0.0.0");
    21.  
    22. NetworkManager.Singleton.StartServer()

    Is there anything missing, am i doing something wrong or has something changed i don't know about?

    Thank you for your help.
     
  2. cris-unity-mm

    cris-unity-mm

    Unity Technologies

    Joined:
    Dec 6, 2019
    Posts:
    6
    Hi! One thing I can suggest is trying to get the payload allocation using GetPayloadAllocationFromJsonAs(). See as an example the MatchPlay sample here
     
  3. Lemior

    Lemior

    Joined:
    Nov 12, 2020
    Posts:
    15
    Hi. I tried it but with the same result.

    This

    Code (CSharp):
    1. Debug.Log("TestA");
    2. Task<MatchmakingResults> task = MultiplayService.Instance.GetPayloadAllocationFromJsonAs<MatchmakingResults>();
    3. Debug.Log(task);
    4. Debug.Log(task.Status);
    5. Debug.Log("TestB");
    6. string value = task.Result.ToString();
    7. Debug.Log(value);
    8. Debug.Log("TestC");
    9.  
    results in

    Code (CSharp):
    1. TestA
    2. System.Threading.Tasks.Task`1[Unity.Services.Matchmaker.Models.MatchmakingResults]
    3. WaitingForActivation
    4. TestB
     
  4. Lemior

    Lemior

    Joined:
    Nov 12, 2020
    Posts:
    15