Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Bug I got error if I click the rewarded ads button second time

Discussion in 'Unity Ads & User Acquisition' started by mfatihbarut, Dec 20, 2021.

Thread Status:
Not open for further replies.
  1. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    If I click rewarded ads button a second time I got the error codes below from the following lines
    It only works again if I close and reopen Unity.

    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@4.0.0/Runtime/Advertisement/Platform/Editor/Placeholder.cs:178)
    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:79)
    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)


    upload_2021-12-20_10-8-56.png

    upload_2021-12-20_10-9-56.png
     
  2. Unity_Quinn

    Unity_Quinn

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    102
    Hi @mfatihbarut,

    Sorry to hear about this.

    Would you mind opening a support ticket with us directly? To open a ticket, please click on the question mark (?) icon at the top of the dashboard and scroll to the File a Ticket section.

    Based on the info I see here, this looks like it could be an issue with the mock ads in the editor for testing, but we would need more information to be sure of anything. Have you tried testing this on a physical device?

    Have a great day!
     
  3. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    I found the reason
    it was Editor's Play Mode Options. When it is enabled ADS doesn't initialize second time or more.
    upload_2021-12-26_1-7-39.png
     
    Last edited: Jan 22, 2022
  4. andresprog

    andresprog

    Joined:
    May 21, 2017
    Posts:
    2
    It works for me!

    I had a problem when I was trying to leave the Play Mode in editor and run again the PlayMode, the console logs shown an error related to an object has been destroyed and you are trying to use that object. I solved this making a temporal fix in the Advertising package version 4.0.0

    This is good solution while we wait that the bug is fixed from the Unity side.

    Note: The good news, the bug should appear only in editor, the script with the problem is running only in editor.

    We need to edit the package code and we have to do the following modifications in order to avoid that Unity PackageManager reimport the package after edit the script and revert our changes.

    Fix Steps:
    1- first move the package in your project, from Library/PackageCache/com.unity.ads.4.0.0 to Packages/com.unity.ads.4.0.0 (This is for allow to edit the package code and can be able to keep your changes in the package, due the Unity Package Manager will not reimport the package in that folder)
    2- After that I modified the script called "PlaceHolder.cs" into the Advertising Package, I attached the script file with my modifications in this post, if you want you could replace this script after move the package folder to the packages folder in your project. It had a problem on initialization.

    If you want to see the error, you could review the Awake method in the script, specifically the "m_LandscapeCanvas" and "m_PortraitCanvas", those fields was not initializing correctly at the second time, I am forcing that initialization in my changes in the script attached.

    I hope this information can be useful for you guys!
     

    Attached Files:

    Last edited: Feb 3, 2022
  5. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    thanks good one
     
    andresprog likes this.
Thread Status:
Not open for further replies.