Search Unity

IUnityAdsListener uses events from a different thread than main thread?

Discussion in 'Unity Ads & User Acquisition' started by CyRaid, Aug 11, 2019.

  1. CyRaid

    CyRaid

    Joined:
    Mar 31, 2015
    Posts:
    134
    As the subject says, I'm running into issues when I do things like use SendMessage during an OnUnityAdsReady. I tried to use UnityEvent with Invoke, still the same. Then tried IEnumerator with "yield return null", and with WaitForSecondsRealtime .. Still complains because it's calling "IsObjectMonoBehaviour" first.. I didn't want to have to make a complete solution just to post messages to main thread but I guess I'll have to.

    Is there a reason why Unity Ads Listener's events must be called from another thread? Not very beginner user friendly..

    Note: It works perfectly in the editor, but not on an actual android. This was a major stumbling block for me to find out my users ad rewards weren't working.

    Edit: Just want to mention this is the same for IL2CPP, and Mono.
     
    michael_looply likes this.
  2. CyRaid

    CyRaid

    Joined:
    Mar 31, 2015
    Posts:
    134
    If anybody wants a quick solution you could always just break down and use SynchronizationContext (like I did). Just assign the ctx variable to SynchronizationContext.Current on Awake (so it knows the context for later):
    Code (CSharp):
    1. public void Awake() {
    2.   ctx = SynchronizationContext.Current;
    3. } // Procedure //
    then use a good ol':
    Code (CSharp):
    1. ctx.Post((callbackData) => someMethod(), callbackData);
    "callbackData" can of course be null or anything you wanna post to the anon func. Works for me (tm).