1
\$\begingroup\$

I'm trying to exclude part of my code when building(android) but keeping it while in the editor for testing purposes.

Using #if UNITY_EDITOR only will result in this code getting built, but using #if UNITY_EDITOR && !UNITY_ANDROID will grey out the code making it unusable in play mode.

\$\endgroup\$
4
\$\begingroup\$

The editor grays them out to remind you the code doesn't work in the current build platform you chose.

For example if in the editor you have chosen Android as the current build platform, it will gray out code that is on other platforms to remind you that this code only works on Android build.

Sometimes you'll write code for debug and testing, so you'll put it in UNITY_EDITOR so it only works in Unity editor.

When you write:

#if (UNITY_EDITOR && !UNITY_ANDROID)
// your code
#endif

it means the platform should be Unity editor and also shouldn't be android to let this code work. So you platform is not both of them. So it doesnt work.

If you only want it not to work on Android just write:

#if !UNITY_ANDROID
// your code
#endif

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.