Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback Should the new Debug Toggle change the DEBUG directive?

Discussion in '2020.1 Beta' started by JoNax97, May 8, 2020.

  1. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
    I'm using the #if DEBUG directive to compile out some logging and safety checks, and noticed that the new Debug toggle doesn't set this directive. I think it would be useful for having a closer performance to release and also quickly test both code paths.
     
    Last edited: May 8, 2020
  2. Awarisu

    Awarisu

    Joined:
    May 6, 2019
    Posts:
    215
    It should, regular .NET projects define DEBUG so by extension if anyone wants to reuse any non-Unity library or code snippet this functionality will break. (same with TRACE)
     
    JoNax97 likes this.
  3. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
    Reading your answer I think I should clarify:
    Currently, the DEBUG directive exists and works as expected(in Editor and Development builds). What I'm asking if for the new toggle to set it to FALSE when working in "Release" mode.
     
    phobos2077 and Awarisu like this.
  4. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
  5. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    In previous versions of Unity, you could also switch to release by disabling the "Editor Attaching" option in Preferences / External tools. And we didn't add DEBUG in that case and our code internally has always set DEBUG when compiling in the editor regardless of debug/release C# configuration.

    Code (CSharp):
    1.     if (developmentBuild || buildingForEditor)
    2.     {   // For System.Diagnostics.Debug class
    3.         outDefines.push_back("DEBUG");
    4.         outDefines.push_back("TRACE");
    5.     }
    6.  
    Changing this behavior would technically be a regression and could cause issues for some users. So the the safest option would be to add a new define, like UNITY_DEBUG and UNITY_RELEASE or similar.
     
    JoNax97 likes this.
  6. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
    Yeah that would work as well. In the end what's needed is the ability to run the code in the same conditions as in a release build.
     
  7. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    We have added a task to our backlog to address this.
     
    JoNax97 likes this.
  8. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
    Thank you!