Standalone Windows define not working correctly?

Currently I have a piece of code that I only want to be executed when the game is built to a standalone windows platform. (Or more specific this project is exported into an assetbundle, the main project loads in this assetbundle and only then should this code be executed, so basically when it’s executed in a build.)

However whenever I encapsulate the code within a standalone define, the code is still compiled in editor, which gets in the way of me building the project.


Here it shows that the debug log is not greyed out.

Is it intended to compile or is this a bug because the documentation also states that it should only compile/execute when built to a standalone windows platform (Unity - Manual: Conditional compilation).

does it really say that though?

i think thats the way it works, (runs even in editor, if that platform is selected)
you could test/fix by adding && !UNITY_EDITOR to that line, to not run in editor.

1 Like

Yeah, I think you are correct and I was wrong in thinking it would only execute the code when built.

Adding the && !UNITY_EDITOR is a nice way to make sure the code is not be run in editor and only compiling when built. But in my specific case I just realized I should just have a custom compiler define setup in the ‘main project’ and that same define in the current script. That way the code will only be executed when the platform and the current script are hooked up. Thought I’d share that, just in case someone finds this thread and has a similair case.

Thanks for the comment mgear!