Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Feature Request callback for reward yes/no

Discussion in 'Unity Mediation' started by mrm83, Aug 31, 2022.

  1. mrm83


    Nov 29, 2014
    Possible to make RewardUserRewarded fire even when user is not rewarded??

    I need to handle different code depending on if user was rewarded or not.. and it can't be done "safely" right now with these 2 callbacks..
    RewardAdClosed - don't know if the user was rewarded or not
    RewardUserRewarded - not fired when user is not rewarded
    playsuga likes this.
  2. jcGrenier


    Unity Technologies

    Feb 23, 2021
    hi @mrm83
    This is an interesting issue, but one we can't really control. The Rewarded callback is provided by the ad networks. We can't guarantee for example that Close will be called after OnRewarded.
    We have some use cases that require that distinction on our end, and what we did is wait a bit after a Close callback to ensure we got the Rewarded callback if there was one.
    You could locally implement something similar. if you get the rewarded callback, you know it was rewarded. if you get Close, start a timer and if by the end you didn't get a rewarded, you can tell it was not. The timer duration is not something we can guarantee, but 1 second should be more than enough (still no guarantees, I recommend you run your own tests)

    Hope that helps! :)
  3. skfldao


    Jul 28, 2019
    Sometimes 1 second isn't enough, so I set it to wait up to 3 seconds.
    At 1 second, many users can't get reward, so I added 2 seconds.

    Declare a bool variable and change it to true in UserRewarded.
    And in AdClosed, I checked that the variable was true and give the reward.

    Code (CSharp):
    1.    void UserRewarded(object sender, RewardEventArgs args)
    2.     {
    3.         // Process for rewarding users
    4.         _userGetReward = true;
    5.     }
    7.     void AdClosed(object sender, EventArgs e)
    8.     {
    9.         StartCoroutine(WaitForRewardCallback());
    10.     }
    12.     IEnumerator WaitForRewardCallback()
    13.     {
    14.         yield return new WaitForSeconds(1f);
    15.         if (_userGetReward)
    16.         {
    17.             // user get reward
    18.             yield break;
    19.         }
    20.         yield return new WaitForSeconds(2f);
    21.         if (_userGetReward)
    22.         {
    23.             // user get reward
    24.             yield break;
    25.         }
    26.         // Process for ad skip users
    27.     }
    Last edited: Sep 6, 2022
    DeclanMcPartlin likes this.
  4. mrm83


    Nov 29, 2014
    Yes, waiting may work, however, this hack fix is not safe implementation.