Unity ADS Problem

Hi, I’m having a problem with UnityADS downloaded from AssetStore, in Unity 5.4, take a look:
Can someone help me on this?

AddComponent with MonoBehaviour is not allowed. Create a class that derives from MonoBehaviour and add it instead.
UnityEngine.Advertisements.Advertisement:Initialize(String, Boolean)

This error point me on this line: coroutineHost = asyncExecGameObject.AddComponent(); from the file AsyncExec.cs from the UnityEngine.Advertisements Class. (line 17)

After it, I receive this another Error:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Advertisements.AsyncExec.runWithCallback[String,WWW] (System.Func3 asyncMethod, System.String arg0, System.Action1 callback) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/Misc/AsyncExec.cs:34)
UnityEngine.Advertisements.UnityAdsEditor.init (System.String gameId, Boolean testModeEnabled, System.String gameObjectName, System.String unityVersion) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/VideoAds/UnityAdsEditor.cs:23)
UnityEngine.Advertisements.UnityAdsExternal.init (System.String gameId, Boolean testModeEnabled, System.String gameObjectName, System.String unityVersion) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/VideoAds/UnityAdsExternal.cs:32)
UnityEngine.Advertisements.UnityAds.Init (System.String gameId, Boolean testModeEnabled) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/VideoAds/UnityAds.cs:68)
UnityEngine.Advertisements.Advertisement.Initialize (System.String appId, Boolean testMode) (at Assets/Standard Assets/UnityAds/Scripts/Advertisement.cs:63)

Can you post example of your code, where you are calling Advertisement.Initialize()

/Rasmus

Hi, thank you for your reply, here is:

using UnityEngine.Advertisements;
void Start
{
Advertisement.Initialize(gameID,testModeAd);
}

I have the same problem. Have you found any solution?

2 Likes

Same problem here. Started occurring after the update to Unity 5.4. Also getting the following error in the console.

AddComponent with MonoBehaviour is not allowed. Create a class that derives from MonoBehaviour and add it instead. Error points to the line where I call Advertisement.Initialize

Sorry for late reply. Does the class from which you are calling Advertisement.Initialize() inherit from MonoBehaviour?

/Rasmus

I use exactly the same code as shown in the example (Integration Guide):

using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements; // Using the Unity Ads namespace.

public class ShowAdOnStart : MonoBehaviour
{
    #if !UNITY_ADS // If the Ads service is not enabled...
    public string gameId; // Set this value from the inspector.
    public bool enableTestMode = true;
    #endif

    IEnumerator Start ()
    {
        #if !UNITY_ADS // If the Ads service is not enabled...
        if (Advertisement.isSupported) { // If runtime platform is supported...
            Advertisement.Initialize(gameId, enableTestMode); // ...initialize.
        }
        #endif

        // Wait until Unity Ads is initialized,
        //  and the default ad placement is ready.
        while (!Advertisement.isInitialized || !Advertisement.IsReady()) {
            yield return new WaitForSeconds(0.5f);
        }

        // Show the default ad placement.
        Advertisement.Show();
    }
}

I’m receiving errors like these:
AddComponent with MonoBehaviour is not allowed. Create a class that derives from MonoBehaviour and add it instead.
UnityEngine.Advertisements.Advertisement:Initialize(String, Boolean)
c__Iterator89:MoveNext() (at Assets/ShowAdOnStart.cs:16)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Advertisements.AsyncExec.runWithCallback[String,WWW] (System.Func3 asyncMethod, System.String arg0, System.Action1 callback) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/Misc/AsyncExec.cs:34)
UnityEngine.Advertisements.UnityAdsEditor.init (System.String gameId, Boolean testModeEnabled, System.String gameObjectName, System.String unityVersion) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/VideoAds/UnityAdsEditor.cs:23)
UnityEngine.Advertisements.UnityAdsExternal.init (System.String gameId, Boolean testModeEnabled, System.String gameObjectName, System.String unityVersion) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/VideoAds/UnityAdsExternal.cs:32)
UnityEngine.Advertisements.UnityAds.Init (System.String gameId, Boolean testModeEnabled) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/VideoAds/UnityAds.cs:68)
UnityEngine.Advertisements.Advertisement.Initialize (System.String appId, Boolean testMode) (at Assets/Standard Assets/UnityAds/Scripts/Advertisement.cs:63)
ShowAdOnStart+c__Iterator89.MoveNext () (at Assets/ShowAdOnStart.cs:16)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

The problem occurs after the Unity 5.4 update. It was working perfectly fine before.

Well, I’d go back to 5.3.4 to continue working.

Ok, reproed in Unity 5.4.0f3 and Unity Ads SDK 1.5. Is this the same version of SDK you are using?

In that case, I would recommend you to upgrade to Unity Ads SDK 2.0, which is available from https://www.assetstore.unity3d.com/en/#!/content/66123

Is that an option, while we investigate the issue closer here?

Thanks,
Rasmus

I’m using the version from Asset Store, not using the “Services” tab from Unity Editor.
Also, I’m having this another problem when trying to “archive” in xCode:

Undefined symbols for architecture armv7:

OBJC_CLASS$_SKStoreProductViewController”, referenced from:

OBJC_CLASS$_CustomStoreProductViewController in UnityAds(UnityAds)

OBJC_METACLASS$_SKStoreProductViewController”, referenced from:

OBJC_METACLASS$_CustomStoreProductViewController in UnityAds(UnityAds)

ld: symbol(s) not found for architecture armv7

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Same problem here. I can not understand you.How could you publish this version without checking it?:slight_smile: .Hire more testers please or hire your girlfriends as testers,if you have financial problems:)

Same problem here after upgrade the proyect from Unity 5.3.4 to Unity 5.4.1p1.

AddComponent with MonoBehaviour is not allowed. Create a class that derives from MonoBehaviour and add it instead.
UnityEngine.Advertisements.Advertisement:Initialize(String, Boolean)
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Advertisements.AsyncExec.runWithCallback[String,WWW] (System.Func3 asyncMethod, System.String arg0, System.Action1 callback) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/Misc/AsyncExec.cs:34)
UnityEngine.Advertisements.UnityAdsEditor.init (System.String gameId, Boolean testModeEnabled, System.String gameObjectName, System.String unityVersion) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/VideoAds/UnityAdsEditor.cs:20)
UnityEngine.Advertisements.UnityAdsExternal.init (System.String gameId, Boolean testModeEnabled, System.String gameObjectName, System.String unityVersion) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/VideoAds/UnityAdsExternal.cs:32)
UnityEngine.Advertisements.UnityAds.Init (System.String gameId, Boolean testModeEnabled) (at Assets/Standard Assets/UnityAds/Scripts/Advertisements/VideoAds/UnityAds.cs:69)
UnityEngine.Advertisements.Advertisement.Initialize (System.String appId, Boolean testMode) (at Assets/Standard Assets/UnityAds/Scripts/Advertisement.cs:52)
UsarAnuncios.Awake () (at Assets/Plugins/UsarAnuncios.cs:61)

I’m also using the version from Asset Store, not using the “Services” tab from Unity Editor.

I just upgraded to Unity Ads SDK 2.0 and continues equal.

Never mind, you need to remove completely the older Unity ads version before import the Unity Ads 2.0 package. Now works correctly.

https://unityads.unity3d.com/help/monetization/2.0-upgrade-guide-unity

Regards.

Just in case anyone runs into these type of problems, make sure you completely remove any unityad plugins or files in the asset folder(s). After getting rid of anything unityad related, then proceed with importing the new SDK and setting up the coding. Should work without any issues.

1 Like

Hello there.

I had a clean version of the SDK but still had the errors. This gentleman there posted a solution that works, but it should be something the Unity dev should have a look at:

Correct, an interface has been changed in Unity 5.4, so you get the “AddComponent with MonoBehaviour is not allowed” message in playmode in editor. However this doesn’t affect games deployed to mobile.

The solution is to upgrade to Unity Ads SDK 2.0 which can be downloaded from https://www.assetstore.unity3d.com/en/#!/content/66123. Ads SDK 2.0 will be integrated in Unity 5.5, and we’re working on deprecating SDK 1.x as soon as possible.

So please for now, use SDK 2.0.

Thanks,
Rasmus

This is a problem I met some days ago. The problem come because if you are using unity ads 1.1 SDK then you update the version unity ads 2.0 asset. So they are 2 assets so if you want to use unity ads 2.0 you need to clear all of files of version 1.1 include “Assets/Standard Assets/UnityAds” (what I missed). Hope it 's helpful.

Just replace this file in plugin and this will be working

3146470–239010–AsyncExec.cs (1.1 KB)