Tiaan
Tiaan

Reputation: 689

Unity Ads UnityEngine.Advertisements library inaccessible

For some reason, I cannot access using UnityEngine.Advertisements; despite my target platform being Android and Unity Ads and builds in ads extension being enabled.

Usually, I only get this error when I compiling for a platform not supporting Unity Ads, I got around this by simply rapping relevant code in #if UNITY_ADS #endif

Here is the "ads" section in Unity services: Unity ads services

And this is how MonoDevelop shows the code if I comment out the if statements: Monodevelop advert manager

Build settings:

Build settings

Error in Unity's console:

Assets/Scripts/Project Management/AdvertManager.cs(5,19): error CS0234: The type or namespace name `Advertisements' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?

I have literally no idea why this isn't working, back when I originally implemented this it was working and stopped at some unknown point as the script was not used until needed for release...

Let me know what other information might be useful...

Thanks in advance!

Upvotes: 1

Views: 5820

Answers (5)

Alex Zonov
Alex Zonov

Reputation: 1

Object conenctSettingsRes = EditorResources.Load("ProjectSettings/UnityConnectSettings.asset"); SerializedObject conenctSettingsObj = new SerializedObject(conenctSettingsRes); bool adsServiceEnabled = conenctSettingsObj.FindProperty("UnityAdsSettings").FindPropertyRelative("m_Enabled").boolValue; string iosGameId = conenctSettingsObj.FindProperty("UnityAdsSettings").FindPropertyRelative("m_IosGameId").stringValue; string androidGameId = conenctSettingsObj.FindProperty("UnityAdsSettings").FindPropertyRelative("m_AndroidGameId").stringValue;

Upvotes: -1

Mohammad Elsayed
Mohammad Elsayed

Reputation: 2066

the answer simply is that when u toggle on the ads service, the text editor does not feel it, just save ur work, restart unity and visual studio or the text editor u r using and it will work

Upvotes: 0

Hameed Ullah Jan
Hameed Ullah Jan

Reputation: 11

may be it's too late to answer but, it can be solved by following these steps:

-close unity (save your project)

-go to project settings folder under the your project directory

  • delete these two files 1. UnityAdsSettings.assets 2. UnityConnectionSettings.assets

-now re-open your project and turn on unity ads under services, you will not see the error again.

Upvotes: 1

Sergey Droba
Sergey Droba

Reputation: 11

Sometimes Unity ads just require reenabling the service and restarting Unity.

Also it doesn't necessary to use ID and initialization, just re-link your project and it will happen automatically

Upvotes: 1

RSon1234
RSon1234

Reputation: 394

I have had this problem several times in the past as well. I don't know if this is the best solution, but I will tell you what I did.

Go the Asset Store in Unity and search for Unity Ads enter image description here

Download and Import this package. Once you do this the errors will go away. But it acts buggy at times. As I said, It may not be the desired solution, but it did work for me and everything worked fine in an app I published to google play.

Upvotes: 1

Related Questions