Search Unity

BlackScreen after/before serving video ads

Discussion in 'Unity Ads & User Acquisition' started by GastonC, Dec 5, 2014.

  1. GastonC

    GastonC

    Joined:
    Aug 26, 2012
    Posts:
    38
    Hello... I'm struggling with this issue for quite some time, and I have no clue what to do about it...

    I have my game integrated with Unity Ads, and display a video ad every few games. Now comes the weird thing.. The ads sometime work great (leaving aside the fill rate, I have a backup system for when the ad is not ready, and Admob shows up).

    The issue is, that sometimes before showing the ad, or after, the whole screen remains black, and can't do anything other than close the whole application & restarting the game.

    Is there any solution or anything about this? Also happened to me with the test application provided by you guys... I have the game already released, and had to take them out because this was crashing my game... Also, Im getting a blog post here on the Unity Blog about the game, and I would like you guys to feature this, that like I mentioned, at the moment I had to take out.

    Thanks, and I hope we can resolve this :D

    Enviroment:

    Unity 4.6
    Have latest version of Unity Ads
    Happens both on Android (s4 mini, galaxy tab 3) & iOS (ipod touch 5th gen, Ipad)
     
  2. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello GastoonC,

    You should post a logcat log when this problem accured. I assure you you will get more quick answer from this forum.
    Because, there is lots of things may crush your app with unity ads. It may be a network connection timeout problem or maybe something with your code. I suspicious about your code actually, because you said error generated both in android and ios.

    Thanks,
     
  3. GastonC

    GastonC

    Joined:
    Aug 26, 2012
    Posts:
    38
    Thanks! I'll post a logcat about the issue...

    I doubt its my code, because like I mentioned, I tried to use the example game that comes with unity ads, and had the same result!
     
  4. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    This is an issue I've been researching. Might have a possible workaround for you.

    Unity Ads essentially pauses the game by setting the timeScale and volume to 0 when an ad is shown. The resume method might not be getting called when the ad is closed.

    There's a MonoBehavior method called OnApplicationPause that takes a bool value. Use this method to set Time.timeScale and AudioListener.volume back to 1.

    Code (CSharp):
    1. public bool usePauseOverride;
    2. private static bool _isPaused;
    3.  
    4. void OnApplicationPause (bool isPaused)
    5. {
    6.     if (!usePauseOverride || isPaused == _isPaused) return;
    7.  
    8.     if (isPaused) Debug.Log ("App was paused.");
    9.     else Debug.Log("App was resumed.");
    10.  
    11.     if (usePauseOverride) PauseOverride(isPaused);
    12. }
    13.  
    14. public static void PauseOverride (bool pause)
    15. {
    16.     if (pause) Debug.Log("Pause game while ad is shown.");
    17.     else Debug.Log("Resume game after ad is closed.");
    18.    
    19.     AudioListener.volume = pause ? 0f : 1f;
    20.     Time.timeScale = pause ? 0f : 1f;
    21.  
    22.     _isPaused = pause;
    23. }
    There's a full integration example here. Let me know how that works out.

    Thanks!
     
    Last edited: Dec 5, 2014
    TebogoWesi, mtdrume and Salazar like this.
  5. Christop

    Christop

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hi I saw this workaround.
    How does it work?
    OnApplicationPause() is a unity callback that get called when the game has lost focus.
    Is this function called once when the Unity Ads show up and go away?
     
  6. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    So the app looses focus to the web view, which displays the ad. As a result, this method is called when an ad is shown and when it is hidden or closed. You can use it to set the volume and timeScale values manually.