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

Bug Ads Initialization Error

Discussion in 'Unity Ads & User Acquisition' started by mstewart52178, Nov 23, 2022.

  1. mstewart52178

    mstewart52178

    Joined:
    Feb 8, 2022
    Posts:
    18
    Getting this 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.ShowSkipButton (UnityEngine.GameObject canvasGameObject) (at Library/PackageCache/com.unity.ads@4.0.0/Runtime/Advertisement/Platform/Editor/Placeholder.cs:183)
    UnityEngine.Advertisements.Placeholder.Show (System.String placementId, System.Boolean allowSkip) (at Library/PackageCache/com.unity.ads@4.0.0/Runtime/Advertisement/Platform/Editor/Placeholder.cs:74)
    UnityEngine.Advertisements.Platform.Editor.EditorPlatform+<>c__DisplayClass14_0.<Show>b__0 () (at Library/PackageCache/com.unity.ads@4.0.0/Runtime/Advertisement/Platform/Editor/EditorPlatform.cs:152)
    UnityEngine.Advertisements.Utilities.CoroutineExecutor.Update () (at Library/PackageCache/com.unity.ads@4.0.0/Runtime/Advertisement/Utilities/CoroutineExecutor.cs:17)

    I have a scene with 2 buttons. One is rewarded ads, the other is interstitial. On the first play, ads are initialized and both buttons work and display test ads. I then exit play mode and hit play to find that the rewarded ad button is no longer interactable, and upon clicking the interstitial button, I get the above error. If I go to
    Window->Services and toggle Ads off then on again, the buttons will work again, but only on the first play.

    I am using these scripts from unity docs:
    Initialize script - Initializing the SDK in Unity
    Interstitial ad - Implementing basic ads in Unity
    Rewarded ad - Implementing rewarded ads in Unity

    I am referencing this youtube video:
    Unity Ads 2022 (Rewarded and Interstitial) - Easy Unity Tutorial - YouTube

    I am using Unity version: 2020.3.22f1
    I have tried these Advertisement package versions through the Package Manager:
    3.7.5 - test ads just don't work at all
    4.0.0 - The provided youtube tutorial above used this version, but i still get the forementioned error above
    latest version 4.4.1 - gives the same error

    any help would be immensely appreciated.
     
  2. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    It looks like the Placeholder object is destroyed after jumping to another scene, did you jump to another scene before showing the second ad? If so, you can set the Placeholder object to not be destroyed. Also, this problem should only happen in the editor, you can test it on a real device.
     
    mstewart52178 likes this.
  3. mstewart52178

    mstewart52178

    Joined:
    Feb 8, 2022
    Posts:
    18
    I'll see about making my Ads Canvas and Ad Manager persist across scenes and testing that.

    Ads Concern on Test Device:
    Since first posting, I had made a build and transferred the resulting .apk file to a kindle fire to at least test the ads since they worked before switching scenes. However, the ads being shown are actual video ads promoting unity and not the placeholder ads that I was seeing in the editor. Is this normal? I had toggled test mode in the editor before building, so I am not sure if this is standard to see.

    Build Size Question:
    When I transferred the .apk to my kindle, the .apk size comes out to 39MB. When I check the app info, the internal storage size is 106MB. Is there a max build or storage limit that Unity or Google allow/reject upon publishing? What build/storage size should I aim to slim my app down to?
     
  4. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
  5. mstewart52178

    mstewart52178

    Joined:
    Feb 8, 2022
    Posts:
    18
    I checked test mode to true in the Services Window under Ads section in the editor. I set test = true in the initializer script. I have also gone to the Gaming Services Dashboard -> Monetization -> Testing ->Test Mode and set both options to "using test ads for all devices". Test ads are still not appearing on the kindle i'm testing with; only displaying real ads. Not sure how to fix this. I am making the build on my pc and copying the build to my kindle directly via charging cable. Could this be a factor? Is it required that the build be downloaded through the Google Play store with test mode on to get the test ads?
     
  6. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    I think what you have done is enough to enable test mode, you can check the device log to see if the initialized Game ID is a different Game ID. Also, I noticed you tested with a Kindle device, maybe try another device. If the problem persists, please contact Unity Ads Support team and provide the Game ID and device log for further investigation: https://docs.unity.com/ads/Support.html
     
  7. krupps

    krupps

    Joined:
    Oct 17, 2017
    Posts:
    159
    When you run initialization Debug.Log your values to check on the device. I have a start scene that runs and it contains all of my singleton classes public class MyController : Singleton<MyController> and that sets them to not destroy. You can find it on the unity github project.

    I use Android Studio then choose the apk to run it on a device/emulator and the debug logging works nice. Maybe that helps.