Rewarded video Ads worked fine only once.

I’m implementing a rewarded video ad system. Everything worked fine when I ran the game the first time. When I ran the game for the second time (without touching anything), I got the following error:

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/com.unity.ads@3.5.2/Runtime/Advertisement/Platform/Editor/Placeholder.cs:179)
UnityEngine.Advertisements.Placeholder.Show (System.String placementId, System.Boolean allowSkip) (at Library/PackageCache/com.unity.ads@3.5.2/Runtime/Advertisement/Platform/Editor/Placeholder.cs:80)
UnityEngine.Advertisements.Platform.Editor.EditorPlatform.Show (System.String placementId) (at Library/PackageCache/com.unity.ads@3.5.2/Runtime/Advertisement/Platform/Editor/EditorPlatform.cs:173)
UnityEngine.Advertisements.Platform.Platform.Show (System.String placementId, UnityEngine.Advertisements.ShowOptions showOptions) (at Library/PackageCache/com.unity.ads@3.5.2/Runtime/Advertisement/Platform/Platform.cs:104)
UnityEngine.Advertisements.Advertisement.Show (System.String placementId) (at Library/PackageCache/com.unity.ads@3.5.2/Runtime/Advertisement/Advertisement.cs:142)
ShowAd.PlaceAd () (at Assets/Project/Scripts/Runtime/UI/ShowAd.cs:50)
UnityEngine.Events.InvokableCall.Invoke () (at :0)
UnityEngine.Events.UnityEvent.Invoke () (at :0)
UnityEngine.UI.Button.Press () (at C:/Program Files/Unity/Hub/Editor/2020.1.17f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2020.1.17f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2020.1.17f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/Program Files/Unity/Hub/Editor/2020.1.17f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2020.1.17f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:376)

After that nothing happes when I call Advertisement.Show nothing happens, no even an error message until I restart Unity. After restarting Unity I get the error above again.

1 Like

It looks like ‘MissingReferenceException’ has the main reason you got errors in your projects

This is obvious, and if the offending code was part of my project then I wouldn’t be posting here. If you take the time to really read the error message it would also be obvious that the error message is generated by the Advertisements package itself:
UnityEngine.Advertisements.Placeholder.HideSkipButton

Do you have any of the “Enter Play Mode” options checked in your project’s Editor settings panel? It sounds like the ads placeholder code isn’t being properly reset between play mode sessions. At any rate, this error won’t affect your builds as they don’t contain the placeholder code.

6960869--819857--Screenshot 2021-03-22 142709.png

1 Like

Yes, I had that option enabled. That was the problem. Thank you very much!

same problem but I don’t have “Enter play mode” options checked

1 Like