Tip for tidying up text 'print'ed to the Unity Console

It’s very unusual to run a game in the console alone!

So it is a very clunky way to present things to a user. However there is a way to make the console text look nicer.

If you’re following the lesson, by the time your NumberWizard code is working it will contain lines like this:

     void StartGame () {

        print ("==========================");
        print ("Welcome to Number Wizard!");
        print ("Now think of a number but don't tell me what it is...");

[and so on]

And therefore your console looks like this:

What you may not know at this point is that the console’s list will only show the first two lines of each message; you can see the whole message below the list by clicking on any specific message line.

You can take advantage of this: if the full text of your ‘print’ statements goes over two lines, the technical information (for example ‘UnityEngine.MonoBehaviour:print(Object)’) will get hidden.

How to make the text go over two lines? We need to add a ‘new-line’ character at the end of each print statement so that two lines get printed instead of one (the second line can be left blank).

You can insert a new-line character by including the two characters ’ \n ’ in your text. (Notice that it is the back-slash character, not the normal slash – MonoDevelop will change the colour of those characters to show that they have a special meaning.)

… So to illustrate this, I change my code to the following:

    void StartGame () {
        print ("==========================\n");
        print ("Welcome to Number Wizard!\n");
        print ("Now think of a number but don't tell me what it is...\n");
        print ("Just make sure it's no more than " + max + "\n");
        print ("... and no less than " + min + ".\n");

[and so on]

1 Like

…which will result in Unity’s console output looking like this:

Much easier to read! :relaxed:


Privacy & Terms