Search Unity

Bug Services live recompile error

Discussion in 'Unity Analytics' started by AdamVlcek, Mar 24, 2023.

  1. AdamVlcek

    AdamVlcek

    Joined:
    Aug 8, 2013
    Posts:
    4
    Hi,

    when I do a live recompile of my app (yes, I'd like to edit the code while app is running in the editor), I get the following error:

    Everything is working OK after normal app initialization - in editor, in production, analytics and purchases work. No fancy stuff, just init services so I can use some basic analytics and IAPs. But recently I decided to make my app more live-recompile friendly. Now everything else works well enough, except for services.

    After the recompile, the app usually runs for a few seconds (sometimes even 30 or something) until the error pops up. No direct call to any service is necessary. And more errors follow. If I try to re-init services by calling await UnityServices.InitializeAsync(options) in OnEnable(), I get the following error:

    If I try to do the re-init call of InitializeAsync later from Update(), I get the same "non-Unity Thread" error, so I don't think the message is really correct.

    My code is based on the https://docs.unity3d.com/Packages/c...al/UnityIAPInitializeUnityGamingServices.html
    Basically it looks like this:
    Code (CSharp):
    1.  
    2.         void Awake()
    3.         {
    4.             InitUnityServices(); // OK here
    5.         }
    6.  
    7.         void OnEnable()
    8.         {
    9.             if (UnityEditor.EditorApplication.isUpdating)
    10.             {
    11.                 InitUnityServices(); // Not so OK here... But other errors pop up.
    12.             }
    13.         }
    14.  
    15.         async void InitUnityServices()
    16.         {
    17.             try
    18.             {
    19.                 var options = new InitializationOptions().SetEnvironmentName(environment);
    20.                 await UnityServices.InitializeAsync(options);
    21.                 InitStore();
    22.             }
    23.             catch (Exception exception)
    24.             {
    25.                 ...
    26.             }
    27.         }

    The current workaround is to not initialise services and anything related in the editor, but I'd rather test my app with as few #if UNITY_EDITORs as possible.

    Tested in Unity 2022.2.9f and Services.Core 1.7.1 and 1.8.1.

    Seems like a bug to me. Does anybody else experience this? Any suggestion what might be wrong on my side? Thanks!
     
    Last edited: Mar 24, 2023
  2. RandolfKlemola

    RandolfKlemola

    Unity Technologies

    Joined:
    May 1, 2020
    Posts:
    130
    Hi @AdamVlcek ,

    Thanks for reaching out! The short answer is that Analytics doesn't support live recompilation, but trying to see if teams outside of the Analytics team can help. I'll let you know! It might just not be possible with Analytics.

    Best,
    Randy