Search Unity

Monetization 3.3.0 Issues

Discussion in 'Package Manager' started by SoloOutlaw, Nov 5, 2019.

  1. SoloOutlaw

    SoloOutlaw

    Joined:
    Feb 29, 2016
    Posts:
    15
    First of all when you install Monetization 3.3.0 it lists duplicate errors.

    I am now using the Package Manager to update in my project.

    So I remove Unity Ads and started over which appeared sort it.

    So maybe others are having the same problem.

    Secondly

    I get the following error just after I view a rewardedVideo in test.


    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.
    GameController.OnUnityAdsDidFinish (System.String placementId, UnityEngine.Advertisements.ShowResult showResult) (at Assets/Scripts/GameController.cs:1533)
    UnityEngine.Advertisements.Platform+<>c__DisplayClass31_1.<Initialize>b__2 (UnityEngine.Advertisements.CallbackExecutor execute) (at Library/PackageCache/com.unity.ads@3.3.1/Runtime/Advertisement/Platform.cs:128)
    UnityEngine.Advertisements.CallbackExecutor.Update () (at Library/PackageCache/com.unity.ads@3.3.1/Runtime/Advertisement/CallbackExecutor.cs:25)

    It's referring to my Lucky Dip Panel.

    This is what I click directly beforehand to activate the advert.

    Now everything is fine until I actually pause my game and return to start menu when this panel is showing.

    I have checked for null states throughout my code and the Lucky Dip Panel always contains something.

    But as soon as it gets to the Finished Listener code it mysteriously has been destroyed.

    Is this a BUG in monetization and is still holding onto data.

    Finally when I upload to Android it works first time issuing me a reward but after that it just must kick out.

    Also the isReady Listener never displays my Debug.log("IsReady").

    Which is odd because I call the isReady function before the Show.

    Can anyone help.
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @SoloOutlaw

    Which version of Unity are you using? Typically, duplicate errors happen when the Ads SDK is installed multiple times. If you install via the Asset Store, then you do not need the package from the Services window or Package Manager.

    https://forum.unity.com/threads/how...ge-package-manager-or-services-window.699005/

    Would you be able to post the ads portion of your GameController script?
     
  3. SoloOutlaw

    SoloOutlaw

    Joined:
    Feb 29, 2016
    Posts:
    15
    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;
    using UnityEngine.EventSystems;
    using UnityEngine.Advertisements;
    public class GameController : MonoBehaviour, IUnityAdsListener
    {

    ---------------------------------------------

    void Awake()
    {

    Advertisement.AddListener(this);
    }

    ---------------------------------------------------

    public static void UnityAdsInitialise() <CALLED WHEN GAMES STARTS
    {
    // Debug.Log("Initialised");
    string gameId = "-------"; //Play Store
    bool testMode = true; //Set to False once live
    Advertisement.Initialize(gameId, testMode);

    }
    ----------------------------------------------------

    public void LuckyDipPanelPressed()
    {
    if (luckyDipPlayOnce)
    {
    luckyDipPanel.SetActive(false);
    luckyDipPanelShadow.SetActive(false);
    return;
    }
    Debug.Log("2" + luckyDipPanel); <<< THE VALUE HAS VALiD CONTENT
    if (Advertisement.IsReady("rewardedVideo"))
    {
    Advertisement.Show("rewardedVideo"); >>>>GOES TO LISTENER
    }
    else
    {
    recieveText.text = "GIFT Unavailable";
    luckyDipPanel.transform.Find("NowLetsDriveText").gameObject.SetActive(true);
    luckyDipPlayOnce = true;

    }



    }
    ----------------------------------------------------


    // Implement IUnityAdsListener interface methods:
    public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    {
    if (placementId == "rewardedVideo")

    // Define conditional logic for each ad completion status:
    if ((showResult == ShowResult.Finished) && !luckyDipPlayOnce)
    {
    //Debug.Log("4"+luckyDipPanel); Would throw up ERROR - Gameobject Destroyed

    // Reward the user for watching the ad to completion.
    luckyDipPanel.transform.Find("NowLetsDriveText").gameObject.SetActive(true);
    recieveText.text = "You have recieved the following GIFT";
    int randomGift = Random.Range(0, 3);
    if (randomGift == 0)
    //helmet
    {
    SoundEffectManager.PlaySound("HelmetPickUp");
    joeyHelmet.SetActive(true);
    helmetWorn = true;
    helmetDamage = 0;
    DisplayHelmetDamage();
    miniHelmetDamageText.gameObject.SetActive(true);
    miniHelmetDamageHeader.gameObject.SetActive(true);
    helmetExists = true;
    carController.miniHelmet.gameObject.SetActive(true);
    luckyDipPanel.transform.Find("coin").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("stopwatch").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("RewardText3").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("RewardText5").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("RewardText4").transform.position += new Vector3(5, 0, 0);
    luckyDipPanel.transform.Find("joeyhelmet").transform.position += new Vector3(5, 0, 0);
    }
    //Extra Time
    if (randomGift == 1)
    {
    SoundEffectManager.PlaySound("BonusStandard");
    IncreaseTime(60);
    luckyDipPanel.transform.Find("coin").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("RewardText5").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("RewardText4").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("joeyhelmet").gameObject.SetActive(false);
    }
    //Extra Points
    if (randomGift == 2)
    {
    SoundEffectManager.PlaySound("CoinPickUp");
    int randomCash = Random.Range(4, 11);
    score += randomCash * 5000;

    newText = luckyDipPanel.transform.Find("RewardText5").GetComponent<Text>();
    newText.text = "£" + (randomCash * 5).ToString() + ",000";
    UpdateScoreText();
    luckyDipPanel.transform.Find("coin").transform.position -= new Vector3(5, 0, 0);
    luckyDipPanel.transform.Find("stopwatch").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("RewardText3").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("RewardText5").transform.position -= new Vector3(5, 0, 0);
    luckyDipPanel.transform.Find("RewardText4").gameObject.SetActive(false);
    luckyDipPanel.transform.Find("joeyhelmet").gameObject.SetActive(false);

    }
    }
    else if (showResult == ShowResult.Skipped)
    {
    // Do not reward the user for skipping the ad.
    recieveText.text = "GIFT denied";
    Debug.Log("The ad was skipped before reaching the end.");

    }
    else if (showResult == ShowResult.Failed)
    {
    recieveText.text = "GIFT Unavailable";
    Debug.Log("The ad failed to be shown.");

    }
    luckyDipPlayOnce = true;
    }
    public void OnUnityAdsReady(string placementId)
    {

    Debug.Log("Advert Ready"); <<<THIS NEVER DISPLAYS
    }
    public void OnUnityAdsDidError(string message)
    {
    // Log the error.
    }
    public void OnUnityAdsDidStart(string placementId)
    {
    // Optional actions to take when the end-users triggers an ad.
    }
     
  4. SoloOutlaw

    SoloOutlaw

    Joined:
    Feb 29, 2016
    Posts:
    15
    Version is Personal 2019.2.5f1
     
  5. SoloOutlaw

    SoloOutlaw

    Joined:
    Feb 29, 2016
    Posts:
    15
    I think I have found a solution.

    void OnDestroy()

    Debug.Log("DestroyAdController");
    myButton.onClick.RemoveListener(ShowRewardedVideo);
    Advertisement.RemoveListener(this);

    I think the active listener stays in memory next time round.
     
  6. YuvMan

    YuvMan

    Joined:
    Mar 30, 2019
    Posts:
    2
    I have this problem and I did not understand what you did to solve it.
     
  7. unity_uBuVvJIGiTENFg

    unity_uBuVvJIGiTENFg

    Joined:
    May 17, 2019
    Posts:
    1
    Hey Solo.

    thank you very much! I had same problem and I spent all afternoon on that. Your solution works :)
     
  8. newtownchan

    newtownchan

    Joined:
    Feb 5, 2020
    Posts:
    1
    Works like a charm. Thanks!!!
     
    Last edited: Apr 13, 2020
  9. Hoorza

    Hoorza

    Joined:
    May 8, 2016
    Posts:
    45

    In case you are still struggling, all you have to do is create OnDestroy() function that will reset the Listener. When your ads script loads up on another level it will add a new Listener anyway. Simply put this function into your script with ads code to reset the Listener and get rid of the problem:
    Code (CSharp):
    1. void OnDestroy()
    2.     {
    3.         Debug.Log("DestroyAdController");
    4.         Advertisement.RemoveListener(this);
    5.     }
     
    ridexpl likes this.
  10. Longshanks87

    Longshanks87

    Joined:
    Oct 14, 2019
    Posts:
    1
    perfect solution, thanks

    1. void OnDestroy()
    2. {
    3. Debug.Log("DestroyAdController");
    4. Advertisement.RemoveListener(this);
    5. }
     
  11. FreDEVOfficial

    FreDEVOfficial

    Joined:
    Aug 20, 2020
    Posts:
    2
    Thanks! this helped me out!
     
  12. warc692

    warc692

    Joined:
    Jul 8, 2019
    Posts:
    4
    Thank you so Much! Been banging my head over this

    1. void OnDestroy()
    2. {
    3. Debug.Log("DestroyAdController");
    4. Advertisement.RemoveListener(this);
    5. }
     
  13. AaEsS

    AaEsS

    Joined:
    Nov 30, 2020
    Posts:
    1
    Thanks a lot!
     
  14. babilGames

    babilGames

    Joined:
    Sep 26, 2020
    Posts:
    3
    You are the best <3
     
  15. Ate-Games

    Ate-Games

    Joined:
    Jan 13, 2021
    Posts:
    4
    void OnDestroy()

    Debug.Log("DestroyAdController");
    myButton.onClick.RemoveListener(ShowRewardedVideo);
    Advertisement.RemoveListener(this);














    WORKKKKKKKKKKKKKKKKKIIIIIIIIIINNNNNNNNNNNNNNNNNNNNNNNNnnnnnnnnnnnnnnnnnnnngggggggggg
    thx
     
  16. AngeloCarvalho

    AngeloCarvalho

    Joined:
    Feb 9, 2021
    Posts:
    1
    Anyone know another solution? i'm using visual scripting with the plugin Bolt and i'm having this same problem And i tried to use this code on the forum but it's not work. I tried to solve using "DontDestroyonLoad" too, but when i used this every time that i loaded my menu scene theres's one more "Ad" Game Object so when i click to watch an Ad it works but give two more rewards and every time that i reload the menu scene theres more "Ad" GameObjects.