#if UNITY_STANDALONE not working correctly

Hi everyone. I have a plugin that requires i set deploy target to Android or iOs, if i’m not on that deployment target (Under buld settings) This plugin will throw compilation errors.

So i need to avoid the scripts that includes and use it when i just download the project from the repo (For jenkins integration)
I need this scripts to do Absolutely nothing when im on “Standalone” deploy target, (Firt project import before switching targets)
And if i use this directive it will trigger True, even after i switch to Android/iOs platforms.

i need to do

// All code disabled until i switch from standalone to Android / iOS
#if !UNITY_STANDALONE
all my code
#endif

Any hints on this would be really appreciated!

When you say “all my code” do you mean all of it? Including the class definition itself? Because then you’ve probably got references to a class that no longer exists in the eyes of the compiler. Otherwise, you’ll have to be more specific about what’s happening.

yes, the entire file, i have the same done with another classes but with other symbols like #USE_ANALYTICS if i dont declare it, the entire class is empty and its not compiled into the game

No - if you don’t declare it, then the class doesn’t exist. If you have code that references that class type then your build will fail to compile because the declaration is missing.

Again, more information about what is happening would be helpful.

Yes i know that… on the files (in that case my analytics manager, i check for the symbol before calling methods or propertyes, i know that)

my problem is that i need that class to basically not exists (i wont calling it anywhere else) until i switch build targets to Android / iOS
When im on standalone that class should do nothing.

Ok. So when you do

what happens?

the code remains, even after i switch from standalone to android platform. (Maybe it has something to do with UNITY_EDITOR")
but i need the code to work while im in editor_android/ios also :frowning:

Can’t you just flip it and say

#if UNITY_ANDROID || UNITY_IOS
1 Like

Lol haven’t tought about that… works like a charm!

Thanks friend!