menu

arrow_back NullReferenceException: Object reference not set to an instance of an object comes up when I want to run an award video. What do I do?

by
1 vote
I have a problem, when I run Rewarded ad in my application, I get a NullReferenceException: Object reference not set to an instance of an object.
private RewardBasedVideoAd rewardBasedVideo;

public void Start()
{
MobileAds.Initialize(initStatus => { });

this.rewardBasedVideo = RewardBasedVideoAd.Instance;

this.RequestRewardBasedVideo();

this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening += this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted += this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed += this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication;
}

private void RequestRewardBasedVideo()
{
string adUnitId = "ca-app-pub-3940256099942544/5224354917";

AdRequest request = new AdRequest.Builder().Build();
this.rewardBasedVideo.LoadAd(request, adUnitId);
}

public void UserOptToWatchAd()
{
if (rewardBasedVideo.IsLoaded())
{
rewardBasedVideo.Show();
}
}
I did everything as in the google guide, but I get this error. If you click on it, it takes you to the line "if (rewardBasedVideo.IsLoaded())". Please help me fix it

2 Answers

by
0 votes
What version of the plugin do you have in unity?

2 Comments

For plugin versions 3.16.0 or higher, you must write the code differently instructions .
aDOPPIO I did everything according to the new guide, and again the same problem(
by
0 votes
NULL, it means there is no object. That is, during the check, you are asking the object, which is NULL, what its state is. This is the error.

Why it's not there - read the script, figure out what you missed and where.