Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Standalone Windows define not working correctly?

Discussion in 'Documentation' started by JZ_Focus, Sep 16, 2019.

  1. JZ_Focus

    JZ_Focus

    Joined:
    Nov 19, 2018
    Posts:
    24
    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.

    Compiledwithindefine.PNG
    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 (https://docs.unity3d.com/Manual/PlatformDependentCompilation.html).
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    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
    Code (CSharp):
    1. && !UNITY_EDITOR
    to that line, to not run in editor.
     
    JZ_Focus likes this.
  3. JZ_Focus

    JZ_Focus

    Joined:
    Nov 19, 2018
    Posts:
    24
    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!