Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Unity Services instances destroyed on Application.Unload

Discussion in 'Unity Analytics' started by I_Live_On, Jun 17, 2023.

  1. I_Live_On

    I_Live_On

    Joined:
    Dec 16, 2021
    Posts:
    2
    Hello,

    We are using Unity as a Library and on ios when we exit back to the native app we call AnalyticsSevice.Flush(), and then Application.Unload. However I see this in the logs.

    Analytics Dispatcher is already flushing.
    UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:LogWarning(Object)
    Unity.Services.Analytics.Internal.Dispatcher:Flush()
    Unity.Services.Analytics.AnalyticsServiceInstance:Flush()
    Unity.Services.Analytics.AnalyticsServiceInstance:GameEnded()
    Unity.Services.Analytics.AnalyticsContainer:OnDestroy()

    Followed by
    InvalidOperationException: Package registration has been locked. Make sure to register service packages in[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)].
    at Unity.Services.Core.Internal.LockedPackageRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    at Unity.Services.Core.Internal.CoreRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in



    Which tells me Analytics is being destroyed. This is a problems because when we go back to the Unity as a Library instance we see this error even before we load our scene which has the code to start up Analytics with await UnityServices.InitializeAsync()
    NullReferenceException: Services require a valid dependency tree to be initialized.
    at Unity.Services.Core.Internal.UnityServicesInternal.InitializeServicesAsync () [0x00000] in <00000000000000000000000000000000>:0

    What is the correct way to initialize and keep services around if using Unity as a Library and Application.Unload?
     
  2. BigIdeaGamesInc

    BigIdeaGamesInc

    Joined:
    May 4, 2021
    Posts:
    1
    Hmm, sorry no help here, but I wanted to mention that I also get that exception on boot. For me it seems to happen around the time IAP is initialized.

    InvalidOperationException: Package registration has been locked. Make sure to register service packages in[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)].
    at Unity.Services.Core.Internal.LockedPackageRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    at Unity.Services.Core.Internal.CoreRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in


    It doesn't seem to cause any issues with my game, but it is very annoying.
     
  3. mbast

    mbast

    Joined:
    Dec 19, 2018
    Posts:
    17
    Same here, doesn't seem to affect anything. But the error shows up upon app initialization.


    Code (CSharp):
    1. InvalidOperationException: Package registration has been locked. Make sure to register service packages in[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)].
    2.   at Unity.Services.Core.Internal.LockedPackageRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    3.   at Unity.Services.Core.Internal.CoreRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    4.   at Unity.Services.Authentication.AuthenticationPackageInitializer.Register () [0x00000] in <00000000000000000000000000000000>:0
    5.  
    6. Uploading Crash Report
    7. InvalidOperationException: Package registration has been locked. Make sure to register service packages in[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)].
    8.   at Unity.Services.Core.Internal.LockedPackageRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    9.   at Unity.Services.Core.Internal.CoreRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    10.   at Unity.Services.Core.Registration.CorePackageInitializer.Register () [0x00000] in <00000000000000000000000000000000>:0
    11.  
    12. Uploading Crash Report
    13. InvalidOperationException: Package registration has been locked. Make sure to register service packages in[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)].
    14.   at Unity.Services.Core.Internal.LockedPackageRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    15.   at Unity.Services.Core.Internal.CoreRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    16.   at Unity.Services.RemoteConfig.CorePackageInitializer.Register () [0x00000] in <00000000000000000000000000000000>:0
    17.  
    18. Uploading Crash Report
    19. InvalidOperationException: Package registration has been locked. Make sure to register service packages in[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)].
    20.   at Unity.Services.Core.Internal.LockedPackageRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    21.   at Unity.Services.Core.Internal.CoreRegistry.RegisterPackage[TPackage] (TPackage package) [0x00000] in <00000000000000000000000000000000>:0
    22.   at UnityEngine.Purchasing.Registration.IapCoreInitializeCallback.Register () [0x00000] in <00000000000000000000000000000000>:0
     
  4. mbast

    mbast

    Joined:
    Dec 19, 2018
    Posts:
    17
    Managed to fix the issue by doing this two things:
    1. Upgrading Odin Inspector to 3.2.1 (last line of the changelog mentions a fix for this type of issue).
    2. Your initial Scene must initialize Unity services, I was initializing some static classes in an empty scene and then loading a second scene that initializes Unity services. Getting rid of the first scene and doing both things at the same scene fixed it for me.
     
  5. Superlabs

    Superlabs

    Joined:
    Jan 23, 2023
    Posts:
    1
    We are having the same issue using UAAL. We have the first scene initialize the UGS through
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    but still getting the same issue. We are initializing UnityIAP in the next scene.
    -sbt