Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Rewarded video no callback on Android

Discussion in 'Unity Ads' started by LSTGames, Jan 7, 2017.

  1. LSTGames

    LSTGames

    Joined:
    Dec 28, 2016
    Posts:
    6
    I don't know what I'm doing wrong but HandleShowResult doesn't get called, the video plays fine and everything works in editor.

    I'm using unity 5.5.0.p3 with the builtin ads and testing on Android 6.0.1. Am I missing some permission, does it need special permission? the video works and the logcat doesn't show any errors.

    Code (CSharp):
    1. public void showRewardedVideo(){
    2.      if(Advertisement.IsReady("rewardedVideo")){
    3.          ShowOptions options = new ShowOptions();
    4.          options.resultCallback = HandleShowResult;
    5.          Advertisement.Show("rewardedVideo", options);
    6.      }
    7. }
    8. private void HandleShowResult(ShowResult result){
    9.      debugText.text = "ads rez: " + result.ToString ();
    10.      switch (result){
    11.          case ShowResult.Finished:
    12.              updateBonusScore(20, true);
    13.              break;
    14.          case ShowResult.Skipped:
    15.              Debug.Log("The ad was skipped before reaching the end.");
    16.              break;
    17.          case ShowResult.Failed:
    18.              Debug.LogError("The ad failed to be shown.");
    19.              break;
    20.      }
    21. }
     
  2. yongilkim

    yongilkim

    Joined:
    Sep 15, 2014
    Posts:
    10
    I also experienced such a phenomenon. I blocked ads from my released apps.
     
  3. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,164
    Hi @LSTGames,

    I copied your code into our example projectx at https://github.com/Unity-Technologies/unity-ads-engineintegration-test in Unity 5.5.0f3, and the callback is called without problems, although on Android 5.1 here (only device I have at home)

    Would it be possible to get access to your project, to see if we can reproduce the issue on our side? E.g. file a bug report including project files from Unity Editor using Help-Report a bug menu item, and post the bug id here (not the full url from mail, as that includes auth token, which gives everyone access to read bug report and project files)

    Thanks,
    Rasmus
     
  4. LSTGames

    LSTGames

    Joined:
    Dec 28, 2016
    Posts:
    6
    it's very late and I will post tomorrow more of what I did to find the problem.

    I have a preloader scene that loads first, then I load another scene Additive and I call SceneManager.UnloadScene when it's done so if I don't call SceneManager.UnloadScene or if I load my scene Single the callback works but this problem is only on Android.
     
  5. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,164
    Ok, retried here with loading another scene using SceneManager.LoadScene and LoadSceneMode.Additive mode as described. Still callback is triggered here.

    At what point do you unload the scene?

    /Rasmus
     
  6. yongilkim

    yongilkim

    Joined:
    Sep 15, 2014
    Posts:
    10
    I think it might be because the version is different.
    I also use 5.5.0p3.
    It is not 5.5.0f1.
     
  7. LSTGames

    LSTGames

    Joined:
    Dec 28, 2016
    Posts:
    6
    Thank you for your time

    I've attached a simplified version of my project, in the file preloader.cs I made 3 cases, please check it out you'll see what I'm talking about, let me know if my code is correct because if I remember correctly you guys recently changed a bit the loading stuff.

    EDIT: I've also test on android 5.1 and unity 5.5.0f3 and still doesn't work
     

    Attached Files:

    Last edited: Jan 9, 2017
  8. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,164
    Hi, sorry for delay. Will check this today

    Thanks,
    Rasmus
     
  9. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    157
    I had the same problem on iOS (opened a thread here, didn't notice this one, sorry). Hope this can be resolved with a quick fix. :(
     
  10. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,164
    @LSTGames, managed to repro issue here with your provided code. If I do a manual initialization of Ads from a script in the "Game" scene in your project (although have to wait a few seconds) it works.

    Will try to step through code to see if I can spot why it fails to call callback in this situation.

    Thanks,
    Rasmus
     
  11. LSTGames

    LSTGames

    Joined:
    Dec 28, 2016
    Posts:
    6
  12. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,164
    Hi, haven't figured out why, but in meantime is a workaround:

    - Import Unity Ads 2.0 SDK from Asset Store instead of using the engine integrated version (disable the "builtin Ads extension" in services window -> Ads -> Advanced)
    - Add following code to a game object in your "Scene" scene:

    Code (CSharp):
    1. void Start ()
    2. {
    3.     Invoke ("InitAds", 5f);
    4. }
    5.  
    6. void InitAds()
    7. {
    8.     #if UNITY_ANDROID
    9.     UnityEngine.Advertisements.Advertisement.Initialize ("(Android game id)");
    10.     #elif UNITY_IOS
    11.     UnityEngine.Advertisements.Advertisement.Initialize ("(iOS game id)");
    12.     #endif
    13. }
    You can see game ids in services window.

    We need to further investigate why this happens in this case, but seems to be related to which scene is active at the time of initialization. Although we have tested Ads SDK with multiple scenes, this case seems to be special.

    /Rasmus
     
  13. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    157
    @rasmus-unity thank you very much, it worked on iOS! Also quite a simple workaround, didn't think about trying it before. We can now submit our game update. :)

    EDIT: it still doesn't work on Android. Video ok, but no callback. :(
    Maybe this helps: my game starts from a "Main" scene and Ads are initialized there. Then, each subsequent scene is loaded with LoadSceneAsync (additive) and merged in "Main". I only load one scene at time.

    EDIT 2: okay, on iOS, if I play and Ad, then load and merge a new scene and play another Ad, it doesn't work anymore. So, as far as I can understand... It works only if I play Ads in the same scene as the initialization.

    EDIT 3: do UnityAds now create some hidden object in the scene that must not be destroyed? Because I wipe all the GameObjects that I don't need between a scene and the other using GetRootGameObjects (and excluding the ones I need), so I suppose I'm deleting something vital to Ads. It already happened with the hidden GameObject "IAPUtil": I was destroying it without knowing it even existed (not nice!) and iAPs were not working.
     
    Last edited: Jan 16, 2017
  14. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    157
    Solved for me. Adding a new post just to notify whoever subscribed the thread.

    The problem was exactly the one I suspected: there is now (I guess from 5.5.0) an hidden GameObject in the scene called "UnityAdsCallbackExecutorObject". In fact I found it inside the GameObject array returned by GetRootGameObjects(), and since I destroy most of the stuff there, that object got destroyed too.
    Keeping the object alive in the scene solved the problem both on iOS and Android.
     
  15. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,164
    Hi, thanks for your feedback and nice finding. We also identified same gameobject and are working on a fix for this.

    Thanks for helping us identifying the root cause of this, and not least provide us with sample code for repro. As said we do have internal tests with multiple scenes, but didn't consider removing the first scene.

    /Rasmus
     
  16. roguesleipnir

    roguesleipnir

    Joined:
    Jan 30, 2017
    Posts:
    2
    I'm also currently encountering the problem. I tried tagging UnityAdsCallbackExecutorObject with DontDestroyOnLoad but it still disappears when loading the next scene.

    I also tried calling Advertisement.Initialize again when I don't find the callback object, but it seems that it can't be recreated or reinitialized.

    Is it only a bug when initializing the ads on the first scene?
     
  17. alex534

    alex534

    Joined:
    Nov 5, 2015
    Posts:
    4
    I know I'm reviving an old thread, but this is just to say that none of the solution I've found worked until I encounter your post DanjelRicci. You are right about the UnityAdsCallbackExecutorObject. This is an issue that still occur on 2017.3.0f3 and we manage to fix it by making a hotfix in our loading screen code. Thank you !
     
  18. Sarazan

    Sarazan

    Joined:
    Apr 29, 2013
    Posts:
    11
    Hey guys, fast forward to 2018.1 and I believe this is still occurring. @rasmus-unity can you provide some updated guidance here?

    I just shipped broken ad code into production and this thread is the only clue on the entire internet as to what might be going wrong. Do I still need to implement a special hack to make sure this executor object stays alive, or... ?
     
  19. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,164
  20. sengweitoo

    sengweitoo

    Joined:
    Nov 24, 2018
    Posts:
    1
    Hey guys, I bump in to similar problem as well, the reward video callback works perfect in unity editor. However, the callback does not called when it is install on Android. I am using Unity Monetization 3.0 and following tutorial here. Thanks in advance guys!
     
  21. smallUser

    smallUser

    Joined:
    Sep 18, 2013
    Posts:
    4
    Same here I am using Unity Monetization 3.0 and Unity 2017.4.17 free edition and set Force test mode ON (i.e. use test ads) for all devices on Operate Dashboards.
    In Editor is okay but on Android
    HandleShowResult not called

    Code (CSharp):
    1.     void Start () {
    2.         adButton = GetComponent<Button> ();
    3.         if (adButton) {
    4.             adButton.onClick.AddListener (ShowAd);
    5.         }
    6.  
    7.         if (Monetization.isSupported) {
    8.             Monetization.Initialize (gameId, true);
    9.         }
    10.     }
    11.  
    12.     void Update () {
    13.         if (adButton) {
    14.             adButton.interactable = Monetization.IsReady (placementId);
    15.         }
    16.     }
    17.  
    18.     void ShowAd () {
    19.         ShowAdCallbacks options = new ShowAdCallbacks ();
    20.         options.finishCallback = HandleShowResult;
    21.         ShowAdPlacementContent ad = Monetization.GetPlacementContent (placementId) as ShowAdPlacementContent;
    22.         ad.Show (options);
    23.     }
    24.  
    25.     void HandleShowResult (ShowResult result) {
    26.         Debug.LogWarning ($">>>>>>Finished show result, result {result}");
    27.         if (result == ShowResult.Finished) {
    28.         } else if (result == ShowResult.Skipped) {
    29.             Debug.LogWarning ("The player skipped the video - DO NOT REWARD!");
    30.         } else if (result == ShowResult.Failed) {
    31.             Debug.LogError ("Video failed to show");
    32.         }
    33.     }