Cannot view unity ads on UiBuilder Canvas

I have a uiButton on unity uiBuilder toolkit, when i press on the button i have called show ads function which needs to play unity ads.However, it doesn't show untiy ads. What might be the reason?

1 Like

Hi there, would you share any script and UI Builder screenshots?

1 Like

Hi ,
I am initializing the Advertisement at first and then using Load and Show ad. The same script is working on Untiy Ui Canvas however this doesn’t work in untiy UiBuilder
here is the code sample below of initilizing the Ads,

//Class1

    public void InitializeAds()
    {
        if (!Advertisement.isInitialized && Advertisement.isSupported)
        {
            Advertisement.Initialize(_gameId, _testMode, this);
        }
    }

Here i am Loading and Showing the ad on button click

//Class2

    public void ShowLoadedAd()
    {
        Advertisement.Load(_adUnitId, this);

        Thread.Sleep(2000);

        // Check if the ad is loaded before attempting to show it:
        if (Advertisement.isInitialized)
        {
            Advertisement.Show(_adUnitId, this);
          //  FindObjectOfType<ToastManager().ShowToast("Show Ads");
        }
        else
        {
            ReloadAds();
        }
    }

//My UiBuilder Class

    private void WatchAds_clicked()
    {
        rewardedAdsButton.ShowLoadedAd();
    }

Here is an image/snap of the UiBuider when i click on this button but i do not see any ad

Hello! How are you registering the click callback on your button? You should have something like this in your UI code:

var button = root.Q<Button>("my-watch-ads-button");
button.clicked += WatchAds_clicked;
1 Like

Greetings,
I wanted to let you know that the button click functionality is indeed working as expected. I've successfully integrated a toast message into Unity for button clicks, and I've also implemented a logging feature for these button clicks. When you click the "WatchAds" button, both the toast message and the log message are displayed flawlessly.

It's worth noting that all buttons and toggles in UiBuilder are functioning correctly, except for the display of ads on top of the UiBuilder canvas, which is currently not working as intended.

public void ShowLoadedAd()
    {
        Advertisement.Load(_adUnitId, this);
        Thread.Sleep(2000);
        // Check if the ad is loaded before attempting to show it:
        if (Advertisement.isInitialized)
        {
            Advertisement.Show(_adUnitId, this);
            Debug.Log("Show ads");
            FindObjectOfType<ToastManager().ShowToast("Show Ads");
        }
        else
        {
            ReloadAds();
        }
    }

The very same code has been seamlessly integrated into the regular UiCanvas. When you click on "WatchAds" by simply integrating pointer down, it beautifully triggers the display of a test advertisement of unity on android device.

    public void OnPointerClick(PointerEventData eventData)
    {
// ..... previous code
        else if (eventData.pointerCurrentRaycast.gameObject.name.Contains("watchAds"))
        {
            WatchAds_BtnClicked();
        }
//..... rest of code
}


private void WatchAds_BtnClicked()
    {
        try
        {
            SaveInteraction saveInteraction = new()
            {
                userId = serverCommunication.loginRoot.data.userId
            };

            rewardedAdsButton.ShowLoadedAd();
        }
        catch (Exception ex)
        {
            FindObjectOfType<ToastManager>().ShowToast(ex.ToString());
        }
    }

9275043--1298940--upload_2023-9-6_8-31-35.png