Getting compilation errors when UNITY_AD compiler tag is used

Hello,

I integrated unity Ads service into my game using the built in Unity Ad service from the editor. According to the docs the code related to Unity.Advertisement is enclosed in #if UNITY_AD #endif however, when I did that the Unity Cloud Build failed to build my project with an error message saying

17: [Unity] Assets/Scripts/Managers/GameManager.cs(681,9): error CS0246: The type or namespace name `ShowOptions' could not be found. Are you missing `UnityEngine.Advertisements' using directive?
18: [Unity] Assets/Scripts/Managers/GameManager.cs(683,9): error CS0841: A local variable `options' cannot be used before it is declared
19: [Unity] Assets/Scripts/Managers/GameManager.cs(702,9): error CS0103: The name `Advertisement' does not exist in the current context
20: [Unity] Assets/Scripts/Managers/GameManager.cs(706,9): error CS0103: The name `Advertisement' does not exist in the current context
21: [Unity] Assets/Scripts/Managers/GameManager.cs(713,22): error CS0103: The name `InternetConnectionCheck' does not exist in the current context

The game runs and compiles with no issues from the editor.

Is there a reason why it fails to build using Cloud Build? Is the UNITY_AD compiler tag not needed if I am using the Ads Service from the Editor?

Thanks

Hi,

It’s “UNITY_ADS”, not “UNITY_AD”, see e.g. https://docs.unity3d.com/ScriptReference/Advertisements.Advertisement.Show.html

Best regards,
Rasmus

@rasmus-unity
That was a typo I made when I created this post. In the project itself I did actually use it correctly, meaning with the S at the end (UNITY_ADS)
However, when using the compiler tag, Cloud Build kept failing with the errors above. When I removed them from my source files, then the build completed successfully.
If you want I can give you read access to my Collab project and you can see the commits with and without the UNITY_ADS

Thanks

Ok, I’ll PM you

/Rasmus