Table of contents
1.
Introduction
2.
Unity Console
2.1.
Errors
2.2.
Warnings
2.3.
Messages
3.
Debug Class
3.1.
Debug.LogError
3.2.
Debug.LogWarning
3.3.
Debug.Log
4.
Frequently Asked Questions
4.1.
What do you understand by Sprite?
4.2.
Can you give some examples of Internal Assets?
4.3.
What are the data types used in Unity?
4.4.
Share some insights on Collisions.
5.
Conclusion
Last Updated: Mar 27, 2024

Unity Console

Author Rupal Saluja
0 upvote

Introduction

In this blog, we will learn about Unity Console, we also learn about Debug Class and its different functions. Unity, being a cross-platform engine, focuses on both 2D and 3D games development and interactive content. There is a complete toolkit for designing, interfaces ensuring that there is minimal use of external programs to get a job done on Unity. 

Unity Console

To see the output of code, we use the console. These outputs will quickly test the lines of code without even adding functionality for testing. You can find the console region above the Assets region, in the labeled tab.

                                                                   Console Tab

Outputs generated in the console are more useful for the programmer than the end-user or player.

To open the console from the main menu of the Unity Editor, you need to select the ‘Window’ tab from Tab Menu. A dropdown menu appears.

From the dropdown menu, select General, and another menu appears. From that menu, we will select Console.

For shortcut key users, press ‘Ctrl+Shift+C’.

Console window

There are many functions of the Debug Class that can be used to generate messages in the Console Window. The prominent three types of messages that appear in the default console, and are related to most of the compiler standards are-

  1. Errors
  2. Warnings
  3. Messages

Errors

Issues or Exceptions that don’t even allow the code to run, are Errors. In this case, the code won’t even proceed if errors are not resolved. Firstly, the programmer is required to resolve the errors, then only the code is expected to generate an output or even run.

Warnings

Such issues that won’t stop code from running, but will pose issues during Runtime, are Warnings. These warnings are needed to be taken care of so that it does not hamper the functionality of the code.

Messages

Messages do not usually highlight issues, they convey something to the user. Messages are much more useful when compared to Errors and Warnings as these not only convey something but also come up with the solution as to what can be done further.

Even when there is console output for Errors, Warnings, and Messages, we still use the Debug class.

Debug Class

Debug class gives us methods that help us in writing messages to the consoles. The process of writing messages is quite similar to how would you create normal output messages in your basic programs. 

Methods of Debug Class are-

  • Debug.LogError
  • Debug.LogWarning
  • Debug.Log

 

Debug.LogError

Now, we will create a script for writing an error to the Console. This will notify when the Delete key is pressed. For this, Debug class method Debug.LogError is used, here we are taking Object as a parameter, in which we are using a String.

void Update(){
    if(movementInput != 0)
         Debug.LogError(“Player not Grounded”);
}

Output:

If you are using this debug error function while developing any game, note that this will stop the game then and there. The game or any application will not proceed further if the errors are not resolved completely.

Debug.LogWarning

Now, we will create a script for writing a simple warning to the Console. This will notify when the Escape key is pressed. For this, Debug class method Debug.LogWarning is used, here we are taking Object as a parameter, in which we are using a String.

void Update(){
    if(movementINput != 0)
         Debug.LogWarning(“Player not Grounded”);
}

Output:

If you are using this debug warning function while developing any game, note that this will not stop the game, unlike the error function. The game or any application will proceed further even if the warning is not paid attention to. Just a warning message will be displayed in the Console Window.

Debug.Log

Now, we will create a script for writing a simple message to the Console. This will notify when the Space key is pressed. For this, Debug class method Debug.Log is used, in which we are taking an Object as a parameter, and we are using a String.

void Update(){
    if(movementInput != 0)
         Debug.Log(movementInput);
         Debug.Log(“InputNumber: {0}, IsGrounded: {1}”, movementInput, IsGrounded());
}

Output:

If you are using this debug log function while developing any game, note that this will not stop the game, unlike the error function. The game or any application will proceed further even if the message is not paid attention to. It will just notify problems to the developer and avoid taking any action by itself.

Frequently Asked Questions

What do you understand by Sprite?

Simple 2D objects that have textures, that is, graphical images on them, are Sprites. By default, Sprites are used when the engine is in 2D mode. When made to appear in 3D space, sprites appear paper-thin.

Can you give some examples of Internal Assets?

Some examples of Internal Assets are as follows:

  • Scenes
  • Animations
  • Materials
  • Scripts
  • Prefabs

What are the data types used in Unity?

Datatypes classify the type of data that can be stored in a particular variable. Certain datatypes used in Unity are ‘int’, ‘float’, ‘double’, ‘bool’, ‘char’, ‘string’.

Share some insights on Collisions.

Collisions are separated from the Sprite itself, attached as separate components, and are calculated on their own. Collider components describe the shape of an object for the purposes of physical collisions.

Conclusion

In this article, we have extensively discussed what Unity Console is all about and what are certain types of messages displayed on the Console Window. We also saw examples of code that will help us write in the Console window. 

We hope that this blog has helped you enhance your knowledge regarding the topic of Unity Console and if you would like to learn more, check out our articles on our platform Coding Ninjas Studio.

For peeps out there who want to learn more about Data Structures, Algorithms, Power programming, JavaScript, or any other upskilling, please refer to guided paths on Coding Ninjas Studio. Enroll in our courses, go for mock tests and solve problems available and interview puzzles. Also, you can put your attention towards interview stuff- interview experiences and an interview bundle for placement preparations. 

Do upvote our blog to help other ninjas grow.

Happy Coding!

Live masterclass