3
\$\begingroup\$

I've seen these two special compilation macros in our code base, What's the difference between #Debug and #DEVELOPEMENT_BUILD in Unity? What's the main purpose of using each?

#if DEBUG
Debug.Log("DEBUG");
#endif

#if DEVELOPMENT_BUILD
Debug.Log("DEVELOPMENT_BUILD");
#endif
\$\endgroup\$

2 Answers 2

5
\$\begingroup\$

From these docs:

You use the DEVELOPMENT_BUILD #define to identify whether your script is running in a player which was built with the “Development Build” option enabled.

On the other hand, DEBUG doesn't exist.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Unity may not have felt like documenting it, but DEBUG certainly exists, and has since at least Unity 3.x. \$\endgroup\$
    – piojo
    Commented Aug 10, 2020 at 11:35
  • 1
    \$\begingroup\$ @piojo If it's not documented, it shouldn't be used, as it may be removed on future versions without notice. \$\endgroup\$ Commented Aug 11, 2020 at 9:00
  • \$\begingroup\$ @TomTsagk Normally I would agree with you, but I think this case is an exception. I've reported a documentation omission bug to Unity, so we'll see what they think. \$\endgroup\$
    – piojo
    Commented Aug 11, 2020 at 9:19
1
\$\begingroup\$

In my testing with Unity 2018 (and it is different in Unity 2020 according to the comments), I found DEBUG is true in the editor and during development builds (it is true during the build so the code is compiled into the build). DEBUG is not true during release builds.

DEVELOPMENT_BUILD is never true in the editor except during development builds (so the code is only runs in development builds, never in the editor). I'm not sure whether editor callbacks (surrounded with #if DEVELOPMENT_BUILD) would run while compiling a development build.

This preprocessor directive is not documented. I reported the omission as a documentation bug, but they may not consider it their responsibility to document .NET conventions.

\$\endgroup\$
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .