Unity ads missing assembly reference?

Hey I’m trying to get unity ads to work in my new project I’m getting:

Assets/Game.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 ads enabled and the build in extension it worked fine in my last project.

Hi,

Have you changed build target to Android or iOS? Alternatively see use of UNITY_ADS conditional in code samples on https://docs.unity3d.com/ScriptReference/Advertisements.Advertisement.Show.html

/Rasmus

oh i feel so stupid thanks had it on windows

No problem. You are not the first to encounter this, so might be we can improve at least the error message.

/Rasmus

UNITY_ADS was not needed when using the Asset Store version of Unity Ads, why the change?

UNITY_ADS is for convenience (at least that was the intention). With Ads SDK package from asset store, you would still need to use e.g. UNITY_IPHONE and/or UNITY_ANDROID conditionals in your code, if shipping for other platforms.

Hope it answers your question.

/Rasmus

With the Asset Store version I was able to build for Windows UWP without the need for UNITY_ADS, or UNITY_IPHONE, etc. Which made my code much cleaner. Now I had to refactor my code with a bunch of ugly #if UNITY_ADS after switching to the internal version.

Ok, you are right. However the reason for this has been concerns about binary sizes, for which reason Ads SDK is only included in builds for Android and iOS.

Remember you can still use the Ads SDK from asset store if you like. Although sounds like you have refactored your code now anyways.

/Rasmus

Unfortunately I had to switch back to the Asset Store version anyway, the internal one does not work with published apps on iOS.

Did you experience this yourself, or is it based on other reports on the forum? We have shipped own games with the integrated Ads SDK to TestFlight and haven’t experienced the mentioned problems.

/Rasmus

Yes, everything was working locally, however via TestFlight it did not work. After reverting to Asset Store version it worked via TestFlight.

Does that mean that it worked in the editor, i.e. you got the “Here would be your ad” placeholder? How about when you deploy to local device for testing?

/Rasmus

It worked in the editor and locally on my device when deployed from Xcode.

Hmm, so worked locally from Xcode but not in TestFlight? Do you still have the TestFlight version available?

I had replaced it, however I just went back to the internal Unity Ads and pushed a new build using TestMode to the iOS TestFlight. It once again repros the issue. I.e. Unity Ads is initialized, but none are available.

I just created a Beta App Review request and added unityads-support@unity3d.com as a tester. Hopefully it gets approved.

Beta App was approved and notification sent to the above email.

I am having the same issue as the original poster: my game was actually working perfectly in 5.5.0, with ads being called as expected, and then out of nowhere I got the “Advertisements namespace does not exist” error.

I was using UNITY_ANDROID in my scripts and after checking this thread I modified them with UNITY_ADS instead. Anyway, all code within is actually greyed (with Android target platform selected for the build, of course) and it is not called at all when the game runs on my phone. It is like the #if directive isn’t recognised at all.
I just upgraded to 5.5.1 (on Win 10) and no difference.
Any suggestion?

Thanks!!

EDIT: found the issue: somehow the “Enable builtin ads extension” in the advanced settings got unchecked!

If you are only targeting Android you should be fine. However if you are also targeting iOS then you need to disable the internal ads extension. See this thread: