Search Unity

Showing un-rewarded ad two times after each other

Discussion in 'Unity Ads & User Acquisition' started by Zwiebel, Aug 25, 2018.

  1. Zwiebel

    Zwiebel

    Joined:
    Jul 23, 2013
    Posts:
    56
    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:

    Code (CSharp):
    1.  if (shouldYield)
    2.         {
    3.             SaveGame();
    4.             if ((numberOfGamesPlayed != 0) && (numberOfGamesPlayed % 5 == 0))
    5.             {
    6.                 Advertisement.Show("video");
    7.             }
    8.        
    9.             yield return new WaitForSeconds(2.0f);
    10.  
    11.             SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    12.         }
    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
     
  2. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    Where is that code being executed from? From Update() handler?

    /Rasmus
     
  3. Zwiebel

    Zwiebel

    Joined:
    Jul 23, 2013
    Posts:
    56
    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.
     
  4. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    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
     
  5. Zwiebel

    Zwiebel

    Joined:
    Jul 23, 2013
    Posts:
    56
    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?
     
  6. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    Hi,

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

    /Rasmus
     
  7. Zwiebel

    Zwiebel

    Joined:
    Jul 23, 2013
    Posts:
    56
    Thank you!