Ads must be initialized before calling show

It is saying “Ads must be initialized before calling show” even tho I initialize them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class Advertise : MonoBehaviour
{
    public string id = "myid";
    // Start is called before the first frame update
    public void Start()
    {
        Advertisement.Initialize(id, true);
        ShowAd();
    }

    // Update is called once per frame
    public void ShowAd()
    {
        Advertisement.Show(id);
    }
}

Hello, it’s because Initialization is asynchronous and your code is for synchronous initialization. Your class should implement the IUnityAdsInitializationListener interface and then you can call Show after OnInitializationComplete() callback was successfully called.
https://docs.unity3d.com/Packages/com.unity.ads@3.7/api/UnityEngine.Advertisements.IUnityAdsInitializationListener.html

3 Likes