Showing un-rewarded ad two times after each other

Hi,

I have implemented Unity Ads to my soon-to-be published application, however I see an interesting thing with un-rewarded ads. When game over is called in my game and I didn’t show any rewarded ads to my user, I would like to show them a normal video ad.

The code what I call looks like this:

 if (shouldYield)
        {
            SaveGame();
            if ((numberOfGamesPlayed != 0) && (numberOfGamesPlayed % 5 == 0))
            {
                Advertisement.Show("video");
            }
        
            yield return new WaitForSeconds(2.0f);

            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }

SaveGame(); saves the users progress to a json file and does nothing else.
After that if it’s not the first game of the user, and the games he played can be divided by 5, I would like to show him/her a video ad, then after the ad returned wait 2 seconds and load a “new” scene.

It works as it should, except the few times it loads two ads after each other instead of one. It happens in the editor and in the android build too (with test mode). I couldn’t reproduce why the issue is happening, so I thought I would ask it here if it’s happening to others too, or if my code causes this.

Any advice would be appreciated

Where is that code being executed from? From Update() handler?

/Rasmus

I forgot to say that, sorry. When my character collide with an enemy (OnCollisionEnter), a method get called which then calls an IEnumerator method with the shouldYield parameter. As far as I know it shouldn’t be called more than one times from here.

I believe it’s caused by your code being called twice somehow. Multiple collisions happening at the same time?

But as such, the SDK on the other hand should skip any subsequent calls to .Show() if an ad has already been started.

Can you check your code to see if you somehow could be in situation where .Show() is called twice within a very short time interval?

/Rasmus

Thank you, I have modified my code to disable collisions on character after the collision, and I haven’t experienced the problem again, yet.

Another question I have thought of, is it a problem if I call the advertisement.initialize everytime when my scene reloads?

Hi,

Subsequent calls to Advertisement.Initialize() will be ignored, so not a problem, on the other hand no need to call multiple times.

/Rasmus

Thank you!