Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Pausing the game pauses test ads? (Unity Mediation Beta v.0.5.1-preview1)

Discussion in 'Unity Mediation' started by 71kris, Aug 13, 2022.

  1. 71kris

    71kris

    Joined:
    Aug 13, 2013
    Posts:
    9
    Hello
    Unity Mediation Beta v.0.5.1-preview1 question.
    Unity 2021.3.8f1

    I couldn't find an answer on the forum so I'd like to ask. If it is explained anywhere in the documentation please let me know where to find it. Thank you.

    The problem (a bug or my wrong implementation):
    In Unity Ads, in the Editor and on Android device I was able to pause the game while 'test ad' was being presented (Interstitial or Rewarded Ads). The game was correctly paused with these two lines of code:
    Code (CSharp):
    1.        
    2.         //Pause game.
    3.         Time.timeScale = 0;
    4.         AudioListener.pause = true;
    Closing the ad was correctly restarting the game where it left off before 'test ad' was started to show.

    Code (CSharp):
    1.      
    2.         //Re-Start game.
    3.         Time.timeScale = 1;
    4.         AudioListener.pause = false;
    In Unity Mediation Beta v.0.5.1-preview1 when I use the same two lines of code to pause the game it appears that it pauses the 'test ad' as well or just the animation at the bottom (thin line)? Both Interstitial and Rewarded Ads.
    Unity Mediation 'test ad' without these two lines of code animates loading/presenting the test ad at the very bottom (thin blue line) correctly and finishes 100% (running from left to right).
    With two lines of code added to ShowInterstitial() it does not animate. The game is paused correctly but the test ad seems to be paused as well?
    Here's my testing code snippet that prevents 'test ad' from running to the end (left to right animation). Could it be that it's only visually affected but the ad works ok?

    Code (CSharp):
    1. public async void ShowInterstitial()
    2.         {
    3.                     //Pause game.
    4.                     Time.timeScale = 0;
    5.                     AudioListener.pause = true;
    6.          
    7.             if (m_InterstitialAd?.AdState == AdState.Loaded)
    8.             {
    9.                 try
    10.                 {
    11.                     var showOptions = new InterstitialAdShowOptions { AutoReload = true };
    12.                     await m_InterstitialAd.ShowAsync(showOptions);
    13.                 }
    14.                 catch (ShowFailedException e)
    15.                 {
    16.  
    17.                 }
    18.             }
    19.         }
    I also tried to place it within 'try - catch' before and after:
    Code (CSharp):
    1. await m_InterstitialAd.ShowAsync(showOptions);
    ...but it made no difference. I also tried to run pause/restart logic in the Update method but it also didn't work for me.
    Your help would be really appreciated.
    Thank you
     
  2. jcGrenier

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    83
    Hi @71kris
    To clarify, by test ad do you mean the ad in the editor? If so, this is expected, these test ads are only there to help setup and test the app flow/ads. They are just Unity UI elements and will behave as such.
    If however you mean test ads on device, this is a serious issue we should investigate.
     
  3. 71kris

    71kris

    Joined:
    Aug 13, 2013
    Posts:
    9
    Hello jcGrenier
    Thank you for your reply. I can confirm that I meant in the Editor. I've just tested on a device and this was not an issue.

    For anyone coming across this - As a workaround I had to add this bit of code (below), otherwise I wouldn't be able to test in the editor and compiling + deploying to a device is not the fastest way of checking things out.

    With this bit of code I have it working both in the Editor and on a device:

    Code (CSharp):
    1. //Pause game.
    2. #if UNITY_EDITOR
    3.             Time.timeScale = 1; // Testing in the Editor it has to run otherwise test ad won't be playing. It also means that enemies can still attack in the background and anything else can be running in the background! Not ideal...
    4. #else
    5.             Time.timeScale = 0; // Testing on a device test ad is playing as expected.
    6. #endif
    7.             AudioListener.pause = true;
    8.  
    I had no such problem in Unity Ads where simply having:

    Code (CSharp):
    1. Time.timeScale = 0;
    2. AudioListener.pause = true;
    ...was working both in the Editor and on a device.
    I still believe that this is a bit of a pain (flaw) in the Unity Mediation implementation.
    Thanks anyway.
     
  4. jcGrenier

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    83
    Thanks for your feedback, we will look into making the editor mock ads more resilient to timescale changes :)
     
unityunity