Cannot Disable UnityAds Auto Initialization

Hello everyone,

I am currently facing the issue regarding ads not loading if the internet connection is not available on application startup. Unity version is 5.3.4f1

I tried to use the workaround described here and here. Unfortunately I am unable to disable the auto-initialization of UnityAds… I have created the UnityAdsBuildProcessor script, placed it in the Editor folder and copy/pasted the following code inside:

using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.Advertisements;

public class UnityAdsBuildProcessor : Editor
{
    [PostProcessScene]
    public static void OnPostprocessScene()
    {
        AdvertisementSettings.enabled = true;
        AdvertisementSettings.initializeOnStartup = false;

        throw new System.ArgumentException();
    }
}

I even threw an exception to make sure this code is being executed. The console output is the one shown in the attached file… The Ads are initialized and only afterwards the exception is thrown (I assume the Ads are initialized before the code disabling Auto-initialization is executed).

Any ideas on how to solve this issue?

Thank you and Best Regards,
Alex.

1 Like

Bump…

Does anyone have an alternative to disabling ads auto-initialization so that I can initialize after ensuring there is an internet connection?

Sorry for late reply to this one. Correct, it seems that the [PostProcessScene] doesn’t apply in editor playmode, however it should work when building on device, at least when I tested here.

Did you try on a device?

-Rasmus

Hello Rasmus,

You are right, I tested it in an Android build and it worked as intended.

Thank you very much for your reply. Somehow I didn’t have notifications enabled and didn’t see it until now.

Best Regards,
Alex.

Why there’s a throw new System.ArgumentException() at the end?