- Home /
How to use #define to turn debug information on/off
Hi,
I want to use #define in my scripts to show debug information;
#define isDebug
...
...
public class Example: Monobehaviour {
void Update() {
#if isDebug
//SHOW DEBUG INFORMATION
#endif
}
}
I have never used them before and the documentation seems vague. If I use it like that, how do I then turn the debug off/on.? Kind Regards
Answer by fafase · Jul 02, 2015 at 10:11 AM
In the PlayerSetting, you can find a Scripting Define Symbols.
You can add your DEBUG case in there and remove it when you go for a production build.
Other way you have to remove the define manually from the script.
Thank you for the reply. Is the only way to have debug information optional easily (from the inspector) and have it not in the build version to do something like this
#if UNITY_EDITOR
public bool showDebug=false;
if(showDebug)
// show debug information...
#endif
using a basic public variable is more flexible since a macro cannot be changed at runtime. So if you go with DEBUG it will be all the way.
now having the public var allows you to change anytime in a more flexible way.
Depending where you need the code, you can use platform macros:
http://docs.unity3d.com/$$anonymous$$anual/PlatformDependentCompilation.html
so if you want your code to run only in editor but not on the device:
#if UNITY_EDITOR
$$anonymous$$y$$anonymous$$ethodOnlyInEditor();
#endif
this will not even go in any build as the compiler will ignore that bit of code. Still when running in the editor, it will run.
$$anonymous$$aybe give a little extra info on what you want to achieve so that we can help you out better.