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?
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.
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.
For a “debug” build (Development build checked in editor) there is a DEVELOPMENT_BUILD symbol. This will eliminate the need for you to manually define it.
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.
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
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.
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
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
}
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.