Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question How to initialize Unity Services without Mediation conditionally?

Discussion in 'Unity Mediation' started by kogi_rc, May 30, 2022.

  1. kogi_rc

    kogi_rc

    Joined:
    Apr 23, 2019
    Posts:
    39
    If I understand Unity Services package loading behaviour correctly, it currently is all-or-nothing loading process.

    The problem is that some parts cannot work by design on selected platforms.
    Is there a way to initialize UnityServices with some modules disabled, conditionally based on target platform? Something that would let us test both PC build (that has no Mediation support) and Android build (that does have Mediation support) without manually removing Mediation package?

    Something along those lines would be nice:

    Code (CSharp):
    1. #if UNITY_ANDROID || UNITY_IOS
    2.             // This would throw "No gameId was set for the mediation service.
    3.             // Please make sure your project is linked to the dashboard when you build your application." on PC standalone
    4.             unityServicesTask = UnityServices.InitializeAsync();
    5. #else
    6.             var opts = new InitializationOptions();
    7.             opts.SetUnityMediationEnabled(false);
    8.             unityServicesTask = UnityServices.InitializeAsync(opts);
    9. #endif
    What is the recommended way to condtionally disable Unity Mediation with either conditional compilation symbol or regular C# condtional statement without disabling everything else in Unity Services.
     
  2. DeclanMcPartlin

    DeclanMcPartlin

    Unity Technologies

    Joined:
    Nov 19, 2020
    Posts:
    146
    Hey @kogi_rc,

    Which version of Mediation are you using? Currently on v0.4, if a platform is not supported (iOS, Android), the initialize will simply complete, although Unity Mediation will not function if calls are made to MediationService.Instance. Could you explain further what exactly happens when you run on PC?

    Thanks for sharing this.
     
  3. kogi_rc

    kogi_rc

    Joined:
    Apr 23, 2019
    Posts:
    39
    - Windows Standalone IL2CPP build (non-store, regular Win PC x64).
    - Mediation version 0.4.1-preview.1, installed from .tar
    - Unity 2021 LTS 2021.3.0

    Full stack trace
    Code (CSharp):
    1. No gameId was set for the mediation service. Please make sure your project is linked to the dashboard when you build your application.
    2. UnityEngine.Logger:Log(LogType, Object)
    3. UnityEngine.Debug:LogError(Object)
    4. Unity.Services.Mediation.<Initialize>d__3:MoveNext()
    5. System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(TStateMachine&)
    6. Unity.Services.Mediation.<Initialize>d__2:MoveNext()
    7. System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(TStateMachine&)
    8. Unity.Services.Mediation.MediationServiceInitializer:Initialize(CoreRegistry)
    9. Unity.Services.Core.Internal.CoreRegistryInitializer:InitializePackageAt(Int32)
    10. Unity.Services.Core.Internal.<>c__DisplayClass7_0:<InitializePackageAt>g__TrackFailureAndProceedInitialization|0(Task)
    11. System.Threading.Tasks.Task:Execute()
    12. System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
    13. System.Threading.Tasks.Task:ExecuteWithThreadLocal(Task&)
    14. System.Threading.Tasks.Task:ExecuteEntry(Boolean)
    15. UnityEngine.WorkRequest:Invoke()
    16. UnityEngine.UnitySynchronizationContext:Exec()
    17.  
    I can recheck and reproduce it tomorrow and provider wider context, let me know if you need me to test anything specific.

    The project is linked to Unity dashboard project (it reads gameId correctly from project settings, Unity Services subsection in Editor test scene) but I'm not sure what to provide as gameId as a replacement for Windows build in this case because Unity Mediation isn't supposed to work there.
     
  4. DeclanMcPartlin

    DeclanMcPartlin

    Unity Technologies

    Joined:
    Nov 19, 2020
    Posts:
    146
    Hi @kogi_rc,

    Thank you for your reply. I see, to confirm, are you still able to run your application? I agree that for this selected platform, this error log is confusing and will be fixed in a later release (thank you for pointing that out). The
    UnityServices.InitializeAsync()
    call itself though should still succeed, it should not throw any exceptions based on my own tests.

    Let us know, thanks!
     
  5. kogi_rc

    kogi_rc

    Joined:
    Apr 23, 2019
    Posts:
    39
    I'm not actually sure if the execution continued properly after this error. I was trying to fix a bug with IL2CPP missing method so it was failing critically shortly after anyway. Maybe the error was in fact only informational message that can be safely ignored.

    Happy to hear that I can just call InitializeAsync and expect that it doesn't need any conditional per-platform treatment. This answers the question to me.
     
  6. DeclanMcPartlin

    DeclanMcPartlin

    Unity Technologies

    Joined:
    Nov 19, 2020
    Posts:
    146
    Hey @kogi_rc,

    Yes, no conditional per platform treatment required would be my expectation. Once you're able to further investigate, do let us know if you're facing any issues regarding this.

    Thanks!