ads working but stop after reloading scene

hey, I got this problem before but I got it fixed by just calling RemoveListener before reload the scene.
This time its not working I don’t know if there’s anything wrong in my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;

public class AdManager : MonoBehaviour, IUnityAdsListener
{
    public GameObject UndoMove;
    public GameObject Player;

    private GameObject[] MovingPlatformsArray;
    private Vector2[] MovingPlatformsPositonArray;

    [HideInInspector]public bool AdReady;

    public static AdManager instance;

    private string GooglePlay_ID = "ididid";
    string rewardedId = "rewardedVideo";
    private bool testMode = true;

    private void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else {
            Destroy(this);
        }
       
       
        Advertisement.AddListener(this);
        Advertisement.Initialize(GooglePlay_ID, testMode);
       
    }

    public void ShowRewardedAd()
    {
        if (Advertisement.IsReady(rewardedId))
        {
            Advertisement.Show(rewardedId);
        }

    }
   
    public void OnUnityAdsDidError(string message)
    {
       
    }

    public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    {
        if (showResult == ShowResult.Finished)
        {
           
            if (PlayerMovement.LastConnectedBody.gameObject.tag=="PlatformMove")
            {
                MovingPlatformsArray = Player.GetComponent<PlayerMovement>().MovingPlatformsArray;
                MovingPlatformsPositonArray = Player.GetComponent<PlayerMovement>().MovingPlatformsPositonArray;
                int i = 0;
                foreach (GameObject MovingPlatform in MovingPlatformsArray)
                {
                    MovingPlatform.transform.position = MovingPlatformsPositonArray[i];
                    i++;
                }
                Player.GetComponent<PlayerMovement>().hj.autoConfigureConnectedAnchor = false;
            }
            Player.transform.position = PlayerMovement.LastMovePosition;
            Player.GetComponent<PlayerMovement>().hj.connectedBody = PlayerMovement.LastConnectedBody;
            Player.GetComponent<PlayerMovement>().hj.connectedAnchor = PlayerMovement.LastConnectedAnchor;
            PlayerMovement.FirstMove = false;
        }
        else if (showResult == ShowResult.Skipped)
        {

        }
        else if (showResult == ShowResult.Failed)
        {

        }
    }

    public void OnUnityAdsDidStart(string placementId)
    {
        if (PlayerMovement.LastConnectedBody.gameObject.tag == "PlatformMove")
        {
            Player.GetComponent<PlayerMovement>().hj.autoConfigureConnectedAnchor = false;
        }
        else
        {
            Player.GetComponent<PlayerMovement>().hj.autoConfigureConnectedAnchor = true;
        }
    }

    public void OnUnityAdsReady(string placementId)
    {

        if (placementId == rewardedId)
        {
            AdReady = true;
        }
        else
        {
            AdReady = false;
        }
    }

    public void DestroyInstance()
    {
        Advertisement.RemoveListener(this);
       
    }


    private void Update()
    {
        if (PlayerMovement.FirstMove == true && AdReady == true)
        {
            UndoMove.SetActive(true);
        }
        else
        {
            UndoMove.SetActive(false);
        }
    }


}

and here is when I reload my scene

public void Restart()
    {
        AdManager.instance.DestroyInstance();
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }

I checked if my function wasn’t getting called with a print but it seems to be working fine.
Tried switching to unity monetization from the asset store but same problem occurs
any help please?

Looks like you’re not resetting the “instance” static variable to null, which means your Start method will always make the component destroy itself after the first scene.

Try adding this to your DestroyInstance method:

instance = null;

I am having the same issue, how do i add this instance = null; and where. i am a newbie to this
my own is rewarded ads
This code keeps destroying my ads when the scene is reloaded

_showAdButton.onClick.RemoveAllListeners();
how do I get it not to destroy when a new scene reloads?
This is for a rewarded ad the ad works fine on the first scene.

1 Like