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

Feature Request callback for reward yes/no

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

  1. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    324
    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

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    86
    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

    skfldao

    Joined:
    Jul 28, 2019
    Posts:
    18
    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.     }
    6.  
    7.     void AdClosed(object sender, EventArgs e)
    8.     {
    9.         StartCoroutine(WaitForRewardCallback());
    10.     }
    11.  
    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.     }
    28.  
     
    Last edited: Sep 6, 2022
    DeclanMcPartlin likes this.
  4. mrm83

    mrm83

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