Why Does Unity & Mono Hate Console Output ?
One very important thing for a programmer to be able to do is see the output of their program ... It seems like MonoDevelop and Unity have decided to make it very difficult to write and test C# scripts ... I probably have been spoiled by using Eclipse for many years ( I love Java ) ...
Here is the issue - 1: why doesn't MonoDevelop output console messages at ALL ?!
2: why do I have to pre-compile my unity project just to view the counsole output from a C# script ?! 3: why doesn't the basic function "System.Console.WriteLine" do anything at all ?! It has been a known problem for a long time !!!
// this should not be a hassle !!!
using UnityEngine;
using System;
public class a : MonoBehaviour {
void Start () {
System.Console.WriteLine("This will never be seen");
print ("I only appear in Unity console");
}
void Update () {}
}
Answer by Alokdo · Apr 01, 2017 at 07:53 PM
Answer for each question:
The Unity editor compiles de code, MonoDevelop and others script editors (like Visual Studio) are just that, editors.
When Unity detects that a script has been changed, added or removed, it compiles all the scripts again, regardless of the importance of the change. Plus, "void Start()" can be called only in playmode (except for editor scripts).
An equivalent in Unity for
System.Console.WriteLine(string);
will beDebug.log(string);
And at last, using System;
is unnecessary, because you're calling System.Console.WriteLine(string);
directly from its namespace.
Code:
using UnityEngine;
public class a : MonoBehaviour {
void Start () {
Debug.log("This will appear in Unity console");
print ("This will also appear in Unity console");
}
void Update () {}
}