Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Ads bug, Missing Reference Error and no ads shows up after reopening the game

Discussion in 'Unity Ads & User Acquisition' started by sharpprogrammer2018, Apr 29, 2021.

  1. sharpprogrammer2018

    sharpprogrammer2018

    Joined:
    Sep 1, 2018
    Posts:
    4
    Hello, I Was using unity advertisement and in test mode, at the first time the ads do the show but when I re-enter in the play mode the ads stop showing, and there comes an error

    I am always having this error: see the attachment

    this all an error came from the Inbuilt advertisement class.
    and I did make a new empty scene added a button and copied the same code. but the error still persisted.
    But when I copied the same code to a new empty project it worked.

    and the behaviors of error:

    in Editor 1) when I edit something and when unity reload assemblies and scripts and then i enter in play mode the ads do a show and no matter how many times I click to show the ads do work without any error
    2)when I exit play mode and renter one error comes up(edited)
    3) after on while in 2nd time in play mode no matter how many times I click the show ad button neither error nor ads do shows up

    this happens in android too
    1) I open game ads do works properly
    2) i close the game and reenter it no ads

    Edit1: Ads do shows up whenever domain is reloaded and when I open the first time the game after domain reloading ads do shows up but when i close and enter the game without reloading the domain it shows error and no ads, and after on nor errors neither ads until domian is reloaded again
     

    Attached Files:

    Last edited: Apr 29, 2021
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
  3. sharpprogrammer2018

    sharpprogrammer2018

    Joined:
    Sep 1, 2018
    Posts:
    4
    yes, I have this option enabled yes, when i check the reload domain and scene, the error has gone it works every time. but only for the editor
     
  4. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    @ap-unity Well, can you please talk to your team about supporting this? It should be a simple enough fix, just clear your static objects when Reload Domain is disabled. See how here.
     
  5. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    @ap-unity Hi, checking back to see if we can get a fix for Reload Domain disabled in Unity Ads?
     
  6. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    Well since nobody from Unity seems to care about this, I've examined the UnityAds package source code and created a Total Hack™️ that developers can use to easily make UnityAds work when Reload Domain is disabled. Just pop this code in one of your ad-related classes:

    Code (CSharp):
    1. #if UNITY_EDITOR
    2.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
    3.     static void Fix_UnityAds()
    4.     {
    5.         var tt = typeof(Advertisement);
    6.         var s_Platform = tt.GetField("s_Platform", BF.Static | BF.NonPublic);
    7.         s_Platform.SetValue(null, null);
    8.         tt.TypeInitializer.Invoke(null, null);
    9.     }
    10. #endif
    Don't forget to add using BF = System.Reflection.BindingFlags; somewhere at the top of the script file.

    Hopefully Unity will see this fix and add their own version of it (no reflection hacks needed) to their package source!
     
    Hoorza and YegorStepanov like this.
  7. YegorStepanov

    YegorStepanov

    Joined:
    Oct 10, 2017
    Posts:
    15
    @tessellation Thank you for sharing ❤️. You have done much more than a Unity worker for a salary.

    I apologize for the emotion, but the Unity `ecosystem` makes you blaze.
    To fix it, they should modify 2 lines in Advertisement.cctor. But no, It would be too easy.

    The required packages for almost every mobile casino are not at all friendly with each other. Nobody cares about it.
    The same store is TMPro with Addressables. It's been 5 years already, let's wait another 5 years.