no line item filled! only at first load

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";
        }
    }
}

Hi @Danny9421 , we don’t recommend you only initialize at the time of showing the ad, instead, we recommend initializing and loading at the beginning of the launch of the app, these requests are not very expensive in terms of bandwidth. In your case, there’s a good chance that there may be some timeouts occurring, but without more information, it would be hard to say.

I hope that helps, thanks for reaching out!

Hi, thanks for your answer.
The user return to the affected main scene every 20-30 seconds. Loading a 30 second video uses enough bandwidth to cause traffic, writing and battery drain and watching is fully optional. If the ad isnt cached over other scenes ad traffic would be more then 10 times higher then my own.
There have to be a better solution, i definitly wont preload the ad.

What informations do you need ? Is there a way to avoid a timeout by delaying any methode in the first run ?

Hi @Danny9421 ,

I wouldn’t recommend storing the ad in a specific scene, for sure. Use a singleton for example to initialize and store the ad across scenes. You should only initialize once per launch cycle (launch of the app → kill the app).

If you absolutely want to only load on the user event click, I would still recommend doing the above for initializing the SDK, then call load then show on the user event click. You’ll also want to keep your waterfall as short as possible, since longer waterfalls significantly impact load times, so keep target eCPMs to a minimum (and low values only, preferably just backfill), and use header bidding as much as possible.

Let us know if that works for you, thanks!

1 Like

Unity Mediation has been deprecated. For more information, see: Important update about Unity Mediation