I have build my app as Appbundle and uploaded to google play console for internal test. When running a rewarded android mediation ad (ad source: unity only) it does work, but:
- The first ad which i try to load does not load and response with “no line item filled!”
The error occurs at: async void LoadAd() - > catch (LoadFailedException erg)
Afterwards every following ad load witouth any issue.
I have a button where a player can click to watch a ad for rewards. I dont preload/preintialize ads because i dont want my user to waste traffic/performance load/battery… which dont use the rewarded ad button at all. So i call the “StartAds” function the first time on button press and fill the wait time with a loading animation.
What could be the reason for this problem and how can i fix it ?
My simplified code:
using System;
using UnityEngine;
using Unity.Services.Core;
using System.Threading.Tasks;
using UnityEngine.UI;
namespace Unity.Services.Mediation.Samples
{
public class AdsShow : MonoBehaviour
{
public MapsDrop mapsDrop;
public int whichQuest;
public string adUnitId = "Rewarded_Android";
public string androidAdUnitId = "REMOVED";
public string iosAdUnitId = "REMOVED";
IRewardedAd m_RewardedAd;
public async void StartAds(int actWhichQuest)
{
try
{
InitializationOptions initializationOptions = new InitializationOptions();
if(Application.platform == RuntimePlatform.Android)
{
initializationOptions.SetGameId(androidAdUnitId);
}else if (Application.platform == RuntimePlatform.IPhonePlayer)
{
initializationOptions.SetGameId(iosAdUnitId);
}else if(Application.platform == RuntimePlatform.WindowsEditor)
{
initializationOptions.SetGameId(androidAdUnitId);
}
await UnityServices.InitializeAsync();
whichQuest = actWhichQuest;
InitializationComplete();
}
catch (Exception e)
{
InitializationFailed(e);
}
}
void OnDestroy()
{
m_RewardedAd?.Dispose();
}
async void ShowRewarded()
{
if (m_RewardedAd?.AdState == AdState.Loaded)
{
try
{
RewardedAdShowOptions showOptions = new RewardedAdShowOptions();
showOptions.AutoReload = true;
await m_RewardedAd.ShowAsync(showOptions);
}
catch (ShowFailedException erg)
{
}
}
}
async void LoadAd()
{
try
{
await m_RewardedAd.LoadAsync();
ShowRewarded();
}
catch (LoadFailedException erg)
{
// Error occurs here
}
}
void InitializationComplete()
{
MediationService.Instance.ImpressionEventPublisher.OnImpression += ImpressionEvent;
m_RewardedAd = MediationService.Instance.CreateRewardedAd(adUnitId);
m_RewardedAd.OnLoaded += AdLoaded;
m_RewardedAd.OnFailedLoad += AdFailedLoad;
m_RewardedAd.OnUserRewarded += UserRewarded;
m_RewardedAd.OnClosed += AdClosed;
LoadAd();
}
void InitializationFailed(Exception error)
{
SdkInitializationError initializationError = SdkInitializationError.Unknown;
if (error is InitializeFailedException initializeFailedException)
{
initializationError = initializeFailedException.initializationError;
}
}
void UserRewarded(object sender, RewardEventArgs e)
{
mapsDrop.CompleteQuestByAdFinish(whichQuest);
}
void AdClosed(object sender, EventArgs args)
{
}
void AdLoaded(object sender, EventArgs e)
{
}
void AdFailedLoad(object sender, LoadErrorEventArgs e)
{
}
void ImpressionEvent(object sender, ImpressionEventArgs args)
{
var impressionData = args.ImpressionData != null ? JsonUtility.ToJson(args.ImpressionData, true) : "null";
}
}
}