Search Unity

[SOLVED] Is unity DEBUG preprocessor always defined? Yes, by design.

Discussion in 'Scripting' started by mcmorry, Apr 26, 2016.

  1. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    Some versions ago (now I'm with 5.3.4f1) I was adding and removing DEBUG preprocessor in the PlayerSettings -> Scripting Define Symbols, to include/exclude some debug only code that also causes memory allocation and lower performance.

    Now even if I remove it, the debug code is always ran.
    The build platform is set as iOS, and doesn't matter if I set to Release mode and uncheck the Development Build. The DEBUG preprocessor is always set.

    Is there any way to fix/resolve this and have the behavior as before?
     
  2. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    :( nobody?
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    If the DEBUG symbol is present in your release build, then that's a bug.

    Issue a bug, include a simple project recreating it if you can.

    If you can't recreate in a bare-bone project, then there may be something wrong in your code. You should look into the .proj files in your project folder and make sure they don't have them in the 'release' settings.
     
  4. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    I'm not saying that is the release build (I will check too, but I don't think is doing it). I have this issue in the editor.
    I was enabling/disabling the "debug" code in the editor, but now I can't disable it anymore.
     
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Oh... you're enabling and disabling in editor...

    you have to rebuild if you change it, make sure everything recompiles when you swap the flag
     
    gendev likes this.
  6. skalev

    skalev

    Joined:
    Feb 16, 2012
    Posts:
    264
    xucian, MarcSpraragen and yyylny like this.
  7. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    I try to reformulate my problem, because it seems i wasn't clear enough.

    I'm using this code for testing:
    Code (CSharp):
    1. #if DEBUG
    2. Debug.Log("DEBUG");
    3. #endif
    4.  
    5. #if DEVELOPMENT_BUILD
    6. Debug.Log("DEVELOPMENT_BUILD");
    7. #endif
    And I'm changing these settings:
    Screenshot 2016-05-04 09.41.13.jpg
    I tried already all the possible combination of "Run in XCode as" Release/Debug, "Developement Build" on/off, and adding and removing from "Scripting Define Symbols" the DEBUG symbol. (And yes, I'm recompiling every time)

    Whatever I tried, when I hit play (not running a build) I always get this output: "DEBUG".

    So my question is: How to remove the DEBUG symbol from the defined ones?
    Some versions ago of Unity (I don't know when) I was able to add it and remove it, and my code was working correctly.
     
  8. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    I think I found the problem. I searched in the whole solution and I found a plugin that I added some time ago that has this code:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. #define DEBUG
    3. #endif
    Not very happy of this... I'll see what to do now.
    Thank you for your help.
     
    KislunA, BitSiesta and lordofduct like this.
  9. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    That sucks...

    Which plugin?
     
  10. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    I already wrote on their forum.
    Anti Cheat Toolkit, and the developer already answered that will fix it soon in the next release
    Google Universal Analytics. Waiting for their answer.

    Anyway, I changed their code and I still get the debug code executed. I can't figure out why.
    So I ended up changing my code. Now I use BRA_DEBUG and finally it works as expected.

    I also tried a new clean empty project, with no symbols defined anywhere.
    Still #if DEBUG is true.
    Very weird.

    I filled a bug report to Unity. Case number 794092
     
    lordofduct likes this.
  11. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    About the issues in the plugins, is correct to say that #define has a file scope. It means that it could not anyway create a global defined DEBUG symbol. The only possible minor issue is that a plugin could start emitting some additional unexpected log, nothing else.
     
  12. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    So in case someone will have the same problem, I received an answer from Unity:
    "The editor is always in DEBUG by design. There are many different functions and messages for debugging which by default work on editor while on standalone or any platforms you need to enable development build for that."
    So #if DEBUG seems to be the same as #if UNITY_EDITOR
     
  13. tomerpeledNG

    tomerpeledNG

    Joined:
    Jul 14, 2017
    Posts:
    81
    Thanks, this was helpful!
     
  14. Cathero

    Cathero

    Joined:
    May 3, 2018
    Posts:
    7
    For anyone stumbling across this thread, a small correction:
    Not quite.

    DEBUG seems to behave like "UNITY_EDITOR | DEVELOPMENT_BUILD", i.e.:

    void Start(){
    #if UNITY_EDITOR
    Debug.Log("This code is executed in the editor only.");
    #endif
    #if DEVELOPMENT_BUILD
    Debug.Log("This code is executed in development builds only.");
    #endif
    #if DEBUG
    Debug.Log("This code is executed in the editor as well as in development builds.");
    #endif
    }
     
    RJ45, Appleguysnake, gaps and 13 others like this.
  15. Kheremos

    Kheremos

    Joined:
    Dec 13, 2017
    Posts:
    17
    I was curious about this topic, and stumbled across this post.

    Correct me if I'm wrong, but to disable DEBUG, can you just put this at the top of a file?
    #undef DEBUG


    From my quick test, it prevents Unity from executing any DEBUG directives. Looks like it works across all files, too, even though I only added the directive to the (absolute) top of one file.

    Also, as expected, it disables methods modified by
     [System.Diagnostics.Conditional("DEBUG")]


    Another note, you could wrap the undef in another directive conditional on a symbol you have better control of.