I know this might sound like a really dumb question, but I am rather confused and can only find answers to the question \'WriteLine vs debug.log\' instead of this one. I ori
For Unity code, I recommend using the static methods in the Debug class, such as Debug.Log, Debug.LogFormat, etc.
There are other variations on these methods such as Debug.LogWarning and Debug.LogError which you can find listed in the first link above. In the Editor you can use the buttons above the log panel to filter the log to only show the messages you want, for example errors only if there is too much noise from your other log messages.
Unity's MonoBehaviour.print method is a thin wrapper around Debug.Log
that has two drawbacks:
context
argument that ties the debug message to the object in the Unity Editor, and the ability to filter by log type in the Editor.MonoBehaviour
, so you can only use it in classes derived from that. The Debug
methods can be used in any of your Unity code.It's also worth noting that all of these log methods are available in a runtime build as well as in the Editor. When they are called in a build, the log messages are available in the MyAppName_Data/output_log.txt
file, where MyAppName
is the name of your executable.
Be careful to not leave too many logging calls in your code when you make a runtime build, especially in methods that are called in every frame like your Update
methods. You can use Application.isEditor to test whether you're running in the editor or not.
It's also possible to use platform dependent compilation for this. This saves a bit of space at runtime, but it is trickier. For example, you might think that UNITY_EDITOR
means you're running in the Editor, but it is also defined in runtime builds!