Search Unity

Game restarting after watching reward ads instead of rewarding player

Discussion in 'Unity Ads & User Acquisition' started by Megalithic, Aug 30, 2017.

  1. Megalithic

    Megalithic

    Joined:
    Apr 21, 2014
    Posts:
    61
    Code (CSharp):
    1. public class AdManager : MonoBehaviour {
    2.  
    3.     GameManager gameManager;
    4.     LivesManager lifeManager;
    5.  
    6.     private void Awake () {    
    7.         if (!Advertisement.isInitialized) {
    8.             Advertisement.Initialize("1513938", true);  //// 1st parameter is String and 2nd is boolean
    9.             Debug.Log("Initialized manually");
    10.         }
    11.     }
    12.  
    13.     private void Start () {
    14.         gameManager = FindObjectOfType<GameManager>();
    15.         lifeManager = FindObjectOfType<LivesManager>();
    16.     }
    17.  
    18.     public void ShowRewardedAd () {
    19.         Debug.Log(Advertisement.IsReady().ToString());
    20.         if (Advertisement.IsReady("rewardedVideo")) {
    21.             Debug.Log(Advertisement.IsReady().ToString());
    22.             var options = new ShowOptions { resultCallback = HandleShowResult };
    23.          
    24.             Advertisement.Show("rewardedVideo", options);
    25.         } else if (!Advertisement.IsReady("rewardedVideo")) {          
    26.             gameManager.AdFailed.gameObject.SetActive(true);
    27.             Invoke("DeactivateAdFailUi", 5f);
    28.         }      
    29.     }
    30.  
    31.     private void HandleShowResult (ShowResult result) {
    32.         switch (result) {
    33.         case ShowResult.Finished:
    34.         gameManager.numberOfTimesAdsSeen = gameManager.numberOfTimesAdsSeen + 1;
    35.         if (gameManager.numberOfTimesAdsSeen == 1) {
    36.             gameManager.deathCount = 3;
    37.             Invoke("Reward2Lives", 0.5f);
    38.         } else if(gameManager.numberOfTimesAdsSeen == 2) {
    39.             gameManager.deathCount = 5;
    40.             Invoke("Reward1Life", 0.5f);
    41.         }
    42.      
    43.         gameManager.AdOption.gameObject.SetActive(false);
    44.         gameManager.SpawnOptionsActivate();
    45.      
    46.         Debug.Log("The ad was successfully shown.");    
    47.         break;
    48.         case ShowResult.Skipped:
    49.         Debug.Log("The ad was skipped before reaching the end.");
    50.         break;
    51.         case ShowResult.Failed:
    52.         Debug.LogError("The ad failed to be shown.");
    53.         gameManager.AdFailed.gameObject.SetActive(true);
    54.         Invoke("DeactivateAdFailUi", 5f);
    55.         break;
    56.         }
    57.     }
    58.  
    59.     void DeactivateAdFailUi() {
    60.         gameManager.AdFailed.gameObject.SetActive(false);
    61.     }
    62.  
    63.     void Reward2Lives() {
    64.         lifeManager.Lives[2].gameObject.SetActive(true);
    65.         lifeManager.Lives[3].gameObject.SetActive(true);
    66.         lifeManager.Lives[4].gameObject.SetActive(true);
    67.     }
    68.  
    69.     void Reward1Life() {
    70.         //lifeManager.Lives[3].gameObject.SetActive(true);
    71.         lifeManager.Lives[4].gameObject.SetActive(true);
    72.     }
    73. }
    Here is my code and I can't seem to figure out whats going on! During test ads there was nothing wrong. But after I have uploaded the game onto the play store, I try it on my S4, the game restarts from the beginning once I watch a reward ad, from a whole new scene, which is an intro scene, I have to go to the playing scene. This problem doesn't seem to show up on my tab 3 10.1" though.

    Does anyone know where to look? Searching the forums, it seems the problem was apparently fixed in a previous version. I have got version 5.6.1f1 and ads version is 2.0. I believe thats the ads version because I got the ads service from the service tab in the editor.

    Update: The problem seems to show up on all mobile phones that I have tested on. I only tried it on one tablet and that the only place its working properly.
     
    Last edited: Aug 30, 2017
  2. mikaisomaa

    mikaisomaa

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    365
    Hi,

    Just making sure - do you have this setting enabled in the developer settings of your phones:

    https://stackoverflow.com/questions/22400859/dont-keep-activities-what-is-it-for

    Don't keep activities should be set to off, otherwise the game activity is discarded when you watch ads and then restarted when ads are closed.

    If this doesn't resolve your issue - please send an e-mail to unityads-support@unity3d.com and provide the following details:
    - your game ID
    - adb logcat logs with Ads in debug mode: https://docs.unity3d.com/ScriptReference/Advertisements.Advertisement-debugMode.html
     
  3. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    96
    I have the same issue:

    Device: S9+
    OS: Android 10
    Unity v2018.4.26LTS
    Unity Ad package: v3.4.9

    App: com.gemidy.darkmaze

    In the editor it works. On the device after watching a rewarded video I can see my app reruns the initialization, so Start, Awake, etc runs again. But of course the callback is not called for watching the video.

    The "Don't keep activities" option is turned off.

    Do you have a solution please?
     
  4. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    96
    Okay, i'm not sure in what's going on here, but it looks like it helps if I use a MonoBehaviour as a listener instead of using a static class. Seemingly both solution works perfectly, but the static way produces that strange issue making the Awake run again. If somebody understands the problem I'd really be glad if explained to me, thank you.