Monetization 3.3.0 Issues

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.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.

@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://discussions.unity.com/t/748070

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

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();
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.
}

Version is Personal 2019.2.5f1

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.

7 Likes

I have this problem and I did not understand what you did to solve it.

Hey Solo.

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

Works like a charm. Thanks!!!

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:

void OnDestroy()
    {
        Debug.Log("DestroyAdController");
        Advertisement.RemoveListener(this);
    }
1 Like

perfect solution, thanks

  • void OnDestroy()
  • {
  • Debug.Log(“DestroyAdController”);
  • Advertisement.RemoveListener(this);
  • }

Thanks! this helped me out!

Thank you so Much! Been banging my head over this

  • void OnDestroy()
  • {
  • Debug.Log(“DestroyAdController”);
  • Advertisement.RemoveListener(this);
  • }

Thanks a lot!

You are the best <3

void OnDestroy()

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

WORKKKKKKKKKKKKKKKKKIIIIIIIIIINNNNNNNNNNNNNNNNNNNNNNNNnnnnnnnnnnnnnnnnnnnngggggggggg
thx

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.