Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Ads video doesn't work after reloading scene

Discussion in 'Unity Ads & User Acquisition' started by PhobosRandom, Nov 12, 2021.

  1. PhobosRandom


    May 13, 2020
    Hi, so basically I have a button to load an ads video, first time I launch the scene, it works like a charm. But as I stop then restart the scene, it doesn't work anymore and it throws to me this error message :

    MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UnityEngine.Advertisements.Placeholder.HideSkipButton (UnityEngine.GameObject canvasGameObject) (at Library/PackageCache/
    UnityEngine.Advertisements.Placeholder.Show (System.String placementId, System.Boolean allowSkip) (at Library/PackageCache/
    UnityEngine.Advertisements.Platform.Editor.EditorPlatform+<>c__DisplayClass15_0.<Show>b__0 () (at Library/PackageCache/
    UnityEngine.Advertisements.Utilities.CoroutineExecutor.Update () (at Library/PackageCache/

    but still also debugging that the ad was played, even tho it wasn't.
    And if I again stop then restart the scene, it doesn't throw anymore the error message, only the successful debug, but still no ads video at all.

    I saw a thread where a person had the same problem, but I didn't see any fix there that worked for me (

    I really don't understand why it's doing this, so if any of you has an idea on how to fix this, it'll be greatly welcomed.

    Here is my code if any of you want to see it :
    Code (CSharp):
    1. public class AdsManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
    2. {
    3. #if UNITY_IOS
    4.     string gameID = "myIosId";
    5. #else
    6.     string gameID = "myAndroidId";
    7. #endif
    9.     [SerializeField] Button showAdButton;
    11.     void Awake()
    12.     {
    13.         if (!Advertisement.isInitialized)
    14.         {
    15.             Advertisement.Initialize(gameID, true, true, this);
    16.         }
    17.         else
    18.         {
    19.             Debug.Log("already initialize");
    20.             LoadAd();
    21.         }
    23.         //showAdButton.interactable = false;
    24.     }
    26.     public void LoadAd()
    27.     {
    28.         Debug.Log("Loading Ad: " + gameID);
    29.         Advertisement.Load("rewardedVideo", this);
    30.     }
    32.     public void ShowAd()
    33.     {
    34.         Debug.Log("play ad");
    36.         Advertisement.Show("rewardedVideo");
    38.         LoadAd();
    39.     }
    41.     public void OnInitializationComplete()
    42.     {
    43.         Debug.Log("Unity Ads initialization complete.");
    44.         LoadAd();
    45.     }
    47.     public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    48.     {
    49.         Debug.Log("Unity Ads initialization complete.");
    50.     }
    52.     public void OnUnityAdsAdLoaded(string placementId)
    53.     {
    54.         Debug.Log("Ad Loaded: " + placementId);
    56.         if (placementId.Equals("rewardedVideo"))
    57.         {
    58.             //showAdButton.interactable = true;
    59.         }
    60.     }
    62.     public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
    63.     {
    64.         Debug.Log($"Error loading Ad Unit {placementId}: {error.ToString()} - {message}");
    65.     }
    67.     public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
    68.     {
    69.         Debug.Log($"Error showing Ad Unit {placementId}: {error.ToString()} - {message}");
    70.     }
    72.     public void OnUnityAdsShowStart(string placementId)
    73.     {
    74.     }
    76.     public void OnUnityAdsShowClick(string placementId)
    77.     {
    78.     }
    80.     public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
    81.     {
    82.     }
    83. }
    Last edited: Nov 12, 2021
  2. Unity_Quinn


    Unity Technologies

    Nov 6, 2020
    Hi @PhobosRandom, thank you for reaching out! Sorry to hear about this!

    First, I'd like to clarify, is this happening in the editor, emulator, or on a physical device? Is this only happening with test ads or with production ads as well? Which device model and OS are you testing with?

    Which version of Unity are you using? Which version of the ads SDK?

    I posted an answer on this thread that sounds similar that may help you, but it is also possible that this is a separate issue. I hope it helps!
  3. PhobosRandom


    May 13, 2020
    The bug is happening in the editor. When I test on a physical device nothing happens (no bugs, but no ads). I've only tested it with the test ads for now.
    The phone I use for testing is a Oneplus 6 on android 11.
    The computer I use is a Dell G3 15 on windows 10.

    I'm testing on unity 2020.3.21f1
    I'm using the ads SDK 3.7.5

    And all the objects I used for the ads system are already on a DontDestroyOnLoad
    Last edited: Nov 17, 2021
  4. Unity_Quinn


    Unity Technologies

    Nov 6, 2020
    Thanks for the additional info.

    I haven't been able to reproduce the issue you're experiencing in the editor using Unity 2020.3.21f1. Would you please create a ticket with us and, ideally, include a project we can use to reproduce the issue?

    I took another look at your code.
    • I noticed that you added a Load call in your Show function. If you're looking to load the next ad immediately after showing, I recommend moving your Load call to the OnUnityAdsShowComplete callback.
    • I also noticed that you've commented out your logic related to the showAdButton. This could be a reason why you do not see any ads when testing on a physical device. Given that I'm not familiar with your complete implementation logic, it is hard to say without a device log or reproducing the issue. Again, creating a support ticket with us and including a build of your app or store link we can test with will help us gather the information we'd need for a more thorough investigation into what's happening.
    When creating your support ticket, please also feel free to link to this forum thread to give the agent some additional context.
  5. PhobosRandom


    May 13, 2020
    Okay, I'll try to do that, I just don't know how to create a ticket.
    Also for the project I need to post with the ticket, you want the project zipped, or a build? And if a build, an exe or an apk ?
  6. Unity_Quinn


    Unity Technologies

    Nov 6, 2020
    Oh, sorry about that! I should've been more clear.

    There are two ways to create a ticket:
    1. Click on the question mark (?) icon at the top right of the dashboard. Scroll down to the file a ticket section. Monetization -> Monetize
    2. Email
    In this case, ideally, we'll want to see your Unity project. You can zip the project folder and attach it to the ticket or provide us with a Google Drive link if that's easier.

    Thanks! :)
  7. PhobosRandom


    May 13, 2020
    Okay thanks a lot for your help :), I've just sent the ticked.
    Unity_Quinn likes this.
  8. tbiz5270


    Sep 11, 2014
    I am still receiving this error with Unity 2019.4.39f1 and Unity Ads 4.2.1.

    I am receiving the same error while testing in the editor (haven't tested on mobile yet, but I assume it will be the same result as OP where an ad simply does not display because of the error). I will test on mobile shortly and edit with my findings.

    This is occurring because the Advertisement.isInitialized flag saves through game (or scene) restarts.

    The first time I run my game, Advertisement.isInitialized is false (which is correct, because i just started the game), so it correctly initializes. An ad is then loaded and showed correctly.

    However, if I stop and re-run the game, Advertisement.isInitialized is already set as true (but it should not be, because I literally just started a fresh run of the game). For this reason, Advertisement.Initialize does nothing, because it thinks it is already initialized. An ad is still loaded when I call Advertisement.Load, but it will not display because of the error OP mentioned.

    The Advertisement.isInitialized will remain true until I make a change to its script, forcing Unity to recompile it. It will then be false again when I run the game, and everything will initialize, load, and display correctly.

    EDIT: After testing on mobile (both iOS and Android), everything seems to be working fine. Advertisement.isInitialized is correctly reset to false after each game restart, allowing it to re-initialize correctly, and therefore ads are successfully loaded and displayed correctly. This problem appears to only be present in the Unity Editor. I suppose stopping the game in the editor behaves differently than exiting the app on mobile, and so doesn't reset the flag correctly.
    Last edited: Jul 7, 2022
  9. mfatihbarut


    Apr 11, 2018
    play mode options may cause it. if you really really need to see the result in editor mode you can temporarily uncheck it by killing your editor performance (I meant very long play button time). I reported it and Unity didn't care about it too much.
    You can also don't care about it too much and you can test your ads in Android platform not in Editor. Besides you can also don't use Unity ads there are lots of other alternatives that I believe much easier to implement.

    SKizil likes this.