Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Unity ADS Problem

Discussion in 'Unity Ads' started by emergki, Aug 1, 2016.

  1. emergki

    emergki

    Joined:
    Oct 15, 2007
    Posts:
    418
    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<MonoBehaviour>(); 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.Func`3 asyncMethod, System.String arg0, System.Action`1 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)
     
  2. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,177
    Can you post example of your code, where you are calling Advertisement.Initialize()

    /Rasmus
     
  3. emergki

    emergki

    Joined:
    Oct 15, 2007
    Posts:
    418
    Hi, thank you for your reply, here is:

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

    Brumby

    Joined:
    Sep 8, 2014
    Posts:
    16
    I have the same problem. Have you found any solution?
     
    schwertfisch and emergki like this.
  5. travman89

    travman89

    Joined:
    Nov 6, 2015
    Posts:
    1
    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
     
  6. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,177
    Sorry for late reply. Does the class from which you are calling Advertisement.Initialize() inherit from MonoBehaviour?

    /Rasmus
     
  7. Brumby

    Brumby

    Joined:
    Sep 8, 2014
    Posts:
    16
    I use exactly the same code as shown in the example (Integration Guide):

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Advertisements; // Using the Unity Ads namespace.
    4.  
    5. public class ShowAdOnStart : MonoBehaviour
    6. {
    7.     #if !UNITY_ADS // If the Ads service is not enabled...
    8.     public string gameId; // Set this value from the inspector.
    9.     public bool enableTestMode = true;
    10.     #endif
    11.  
    12.     IEnumerator Start ()
    13.     {
    14.         #if !UNITY_ADS // If the Ads service is not enabled...
    15.         if (Advertisement.isSupported) { // If runtime platform is supported...
    16.             Advertisement.Initialize(gameId, enableTestMode); // ...initialize.
    17.         }
    18.         #endif
    19.  
    20.         // Wait until Unity Ads is initialized,
    21.         //  and the default ad placement is ready.
    22.         while (!Advertisement.isInitialized || !Advertisement.IsReady()) {
    23.             yield return new WaitForSeconds(0.5f);
    24.         }
    25.  
    26.         // Show the default ad placement.
    27.         Advertisement.Show();
    28.     }
    29. }
    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)
    <Start>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.Func`3 asyncMethod, System.String arg0, System.Action`1 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+<Start>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.



     
  8. emergki

    emergki

    Joined:
    Oct 15, 2007
    Posts:
    418
    Well, I'd go back to 5.3.4 to continue working.
     
  9. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,177
    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
     
  10. emergki

    emergki

    Joined:
    Oct 15, 2007
    Posts:
    418
    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)
     
  11. ozgurhazar

    ozgurhazar

    Joined:
    Aug 30, 2014
    Posts:
    19
    Same problem here. I can not understand you.How could you publish this version without checking it?:) .Hire more testers please or hire your girlfriends as testers,if you have financial problems:)
     
  12. www_3dart_es

    www_3dart_es

    Joined:
    May 24, 2013
    Posts:
    201
    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.Func`3 asyncMethod, System.String arg0, System.Action`1 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.
     
    Last edited: Sep 16, 2016
  13. www_3dart_es

    www_3dart_es

    Joined:
    May 24, 2013
    Posts:
    201
    I just upgraded to Unity Ads SDK 2.0 and continues equal.
     
  14. www_3dart_es

    www_3dart_es

    Joined:
    May 24, 2013
    Posts:
    201
  15. Ohyouknow

    Ohyouknow

    Joined:
    Oct 23, 2013
    Posts:
    62
    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.
     
    rasmus-unity likes this.
  16. GiyomuGames

    GiyomuGames

    Joined:
    Jan 12, 2015
    Posts:
    61
  17. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,177
    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
     
  18. cradiff

    cradiff

    Joined:
    Feb 7, 2015
    Posts:
    55
    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.
     
  19. HafizAli

    HafizAli

    Joined:
    Jul 18, 2016
    Posts:
    2
    Just replace this file in plugin and this will be working
     

    Attached Files: