I’m working on an Android game and I want to add AdMob ads to my game. I have added Banner and interstitial Views, but I’m having an issue with the RewardBasedVideoAd specifically on the OnAdRewarded
event. When the user closes the video and returns to the game to earn their reward, the game crashes immediately.
After many tries, I found the problem to be with the code gameObject.SetActive(true)
and gameObject.SetActive(false)
. When I deactivate the game panel UI and activate the reward panel UI, the game crashes immediately.
How can I solve this issue? Why does the game crash when I use gameObject.SetActive
?
Request reward code
public void RequestReward()
{
AdRequest request = new AdRequest().Builder().Build();
this.rewardAd.LoadAd(request, rewardAdId);
rewardAd.OnAdLoaded += this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded += this.HandleOnAdRewarded;
rewardAd.OnAdClosed += this.HandleOnRewardAdClosed;
}
Handlers
public void HandleOnRewardAdLoaded(object sender, EventArgs args)
{
if(rewardAd.IsLoaded())
{
rewardAd.Show();
}
}
public void HandleOnAdRewarded(object sender, EventArgs args)
{
gamePanel.SetActive(false);
rewardPanel.SetActive(true);
}
public HandleOnRewardAdClosed(object sender, EventArgs args)
{
rewardAd.OnAdLoaded -= this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded -= this.HandleOnAdRewarded;
rewardAd.OnAdClosed -= this.HandleOnRewardAdClosed;
}
I’m having an issue with the RewardBasedVideoAd in my Android game. When the user closes the video and returns to the game to earn their reward, the game crashes. I have identified the problem to be with the code gameObject.SetActive(true)
and gameObject.SetActive(false)
when deactivating the game panel UI and activating the reward panel UI.
How can I solve this issue? Why does the game crash when I use gameObject.SetActive
?
Request reward code
public void RequestReward()
{
AdRequest request = new AdRequest().Builder().Build();
this.rewardAd.LoadAd(request, rewardAdId);
rewardAd.OnAdLoaded += this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded += this.HandleOnAdRewarded;
rewardAd.OnAdClosed += this.HandleOnRewardAdClosed;
}
Handlers
public void HandleOnRewardAdLoaded(object sender, EventArgs args)
{
if(rewardAd.IsLoaded())
{
rewardAd.Show();
}
}
public void HandleOnAdRewarded(object sender, EventArgs args)
{
gamePanel.SetActive(false);
rewardPanel.SetActive(true);
}
public HandleOnRewardAdClosed(object sender, EventArgs args)
{
rewardAd.OnAdLoaded -= this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded -= this.HandleOnAdRewarded;
rewardAd.OnAdClosed -= this.HandleOnRewardAdClosed;
}
I’m having an issue with the RewardBasedVideoAd in my Android game. When the user closes the video and returns to the game to earn their reward, the game crashes. I have identified the problem to be when deactivating the game panel UI and activating the reward panel UI using gameObject.SetActive(true)
and gameObject.SetActive(false)
.
How can I solve this issue? Why does the game crash when I use gameObject.SetActive
?
Request reward code
public void RequestReward()
{
AdRequest request = new AdRequest().Builder().Build();
this.rewardAd.LoadAd(request, rewardAdId);
rewardAd.OnAdLoaded += this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded += this.HandleOnAdRewarded;
rewardAd.OnAdClosed += this.HandleOnRewardAdClosed;
}
Handlers
public void HandleOnRewardAdLoaded(object sender, EventArgs args)
{
if(rewardAd.IsLoaded())
{
rewardAd.Show();
}
}
public void HandleOnAdRewarded(object sender, EventArgs args)
{
gamePanel.SetActive(false);
rewardPanel.SetActive(true);
}
public HandleOnRewardAdClosed(object sender, EventArgs args)
{
rewardAd.OnAdLoaded -= this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded -= this.HandleOnAdRewarded;
rewardAd.OnAdClosed -= this.HandleOnRewardAdClosed;
}
I’m having an issue with the RewardBasedVideoAd in my Android game. When the user closes the video and returns to the game to earn their reward, the game crashes. I have identified the problem to be when deactivating the game panel UI and activating the reward panel UI using gameObject.SetActive(true)
and gameObject.SetActive(false)
.
How can I solve this issue? Why does the game crash when I use gameObject.SetActive
?
Request reward code
public void RequestReward()
{
AdRequest request = new AdRequest().Builder().Build();
this.rewardAd.LoadAd(request, rewardAdId);
rewardAd.OnAdLoaded += this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded += this.HandleOnAdRewarded;
rewardAd.OnAdClosed += this.HandleOnRewardAdClosed;
}
Handlers
public void HandleOnRewardAdLoaded(object sender, EventArgs args)
{
if(rewardAd.IsLoaded())
{
rewardAd.Show();
}
}
public void HandleOnAdRewarded(object sender, EventArgs args)
{
gamePanel.SetActive(false);
rewardPanel.SetActive(true);
}
public HandleOnRewardAdClosed(object sender, EventArgs args)
{
rewardAd.OnAdLoaded -= this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded -= this.HandleOnAdRewarded;
rewardAd.OnAdClosed -= this.HandleOnRewardAdClosed;
}
I’m having an issue with the RewardBasedVideoAd in my Android game. When the user closes the video and returns to the game to earn their reward, the game crashes. I have identified the problem to be when activating the reward panel UI using gameObject.SetActive(true)
and gameObject.SetActive(false)
.
How can I solve this issue? Why does the game crash when I use gameObject.SetActive
?
Request reward code
public void RequestReward()
{
AdRequest request = new AdRequest().Builder().Build();
this.rewardAd.LoadAd(request, rewardAdId);
rewardAd.OnAdLoaded += this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded += this.HandleOnAdRewarded;
rewardAd.OnAdClosed += this.HandleOnRewardAdClosed;
}
Handlers
public void HandleOnRewardAdLoaded(object sender, EventArgs args)
{
if(rewardAd.IsLoaded())
{
rewardAd.Show();
}
}
public void HandleOnAdRewarded(object sender, EventArgs args)
{
gamePanel.SetActive(false);
rewardPanel.SetActive(true);
}
public HandleOnRewardAdClosed(object sender, EventArgs args)
{
rewardAd.OnAdLoaded -= this.HandleOnRewardAdLoaded;
rewardAd.OnAdRewarded -= this.HandleOnAdRewarded;
rewardAd.OnAdCl