Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Other Use UDP Initialisation in a async task not initialising

Discussion in 'Unity Distribution Portal (UDP)' started by ManuelRauber, Apr 13, 2022.

  1. ManuelRauber


    Apr 3, 2015

    in my project I use UniTask to streamline async stuff in Unity. I had a basic UDP integration that worked with the Qoo App Store.

    In case you're not familiar with UniTask, it explains here that all async/await is run on the Unity main thread: (except if you use it's method SwitchToThreadPool which I do not use).

    Then I wanted to do some deeper integration with Qoo App Store, which is also quite Callback-heavy. In that case, I normally start using UniTask to get a nice async/await-able API for 3rd party code.

    To start, I simply changed how UDP is initialized from a callback approach to a task approach, like this:

    Code (CSharp):
    1. public static class UdpIntegration
    2. {
    3.   private class GameStoreUdpListener : IInitListener
    4.   {
    5.     private readonly UniTaskCompletionSource<bool> _taskCompletionSource;
    7.     public GameStoreUdpListener(UniTaskCompletionSource<bool> taskCompletionSource)
    8.     {
    9.       _taskCompletionSource = taskCompletionSource;
    10.     }
    12.     public void OnInitialized(UserInfo userInfo)
    13.     {
    14.       Debug.Log($"UDP Successfully initialized for {userInfo.Channel}");
    15.       _taskCompletionSource.TrySetResult(true);
    16.     }
    18.     public void OnInitializeFailed(string message)
    19.     {
    20.       Debug.LogError($"UDP initialization failed: {message}");
    21.       _taskCompletionSource.TrySetResult(false);
    22.     }
    23.   }
    25.   public static UniTask<UdpInitializationResult> InitializeAsync()
    26.   {
    27.     Debug.Log("Starting UDP Initialization");
    29.     var taskCompletionSource = new UniTaskCompletionSource();
    31.     StoreService.Initialize(new GameStoreUdpListener(taskCompletionSource));
    33.     return taskCompletionSource.Task;
    34.   }
    35. }
    In my start up behaviour I use it like this:

    Code (CSharp):
    1. [UsedImplicitly]
    2. private async UniTaskVoid Start()
    3. {
    4.   // Other async/await init stuff
    6. #if UNITY_UDP
    7.   var initializationResult = await UdpIntegration.InitializeAsync();
    8. #endif
    10.   // Other async/await init stuff
    11. }
    When I take a look at Android Logcat during the startup, I notice, that I get the message Starting UDP Initialization and then nothing. No other log message shows up and the init of the app hangs, which makes sense, because taskCompletionSource is never completed, because the IInitListener callbacks are not called.

    Shouldn't it be possible to use it that way? Or could there be anything else that prevents calling the callbacks?



    * Latest 2021.2
    * Latest UDP Package
    Last edited: Apr 13, 2022
  2. ManuelRauber


    Apr 3, 2015