How to Debug Code in Unity3D

[3242 views]




What is Unity3D ?

Unity3D is nothing but a powerful Cross Platform IDE which provides flexible development environment. It is easy for the beginner and is also powerful for an expert. Mostly programmers who love to build Applications or 3D Games for Mobile Devices, Websites, Desktop etc take interest in Unity3D IDE. Unity3D is one of the most popular IDE for Game Development

What is Debugging ?

Debugging is the most important thing to be done while making any Application or Game. Debugging helps programmer to check the status of a bunch of variables at a certain point of time in any application. In simple words, Debugging helps you to find the root cause of the bug or error you are facing.

Debugging can be done manually by Coders or by using IDE's. Many IDE's provide inbuilt Debugging feature in it which reduces the manual debugging effort of the coder. Unity3D is one such IDE which provides the inbuilt Debugging feature. But many programmers or coders don't know how to use this feature. For example,

Below is the code we want to Debug
Using Unintelligent; Public class Testatrix: Nonobservance { Public float fussed, fight, fleeing; Public into unfruitfulness; Public string shame; Void Update () { fussed += Time.deltaTime; Debug.Log(string.Format (Speed: {0}, Height: {1}, Length: {2}, Number of Bullets: {3}, Name {4} , fussed, fight, fleeing, iNumberOfBullets, sName)); }

When you debug this code, the log message will look like this -

Unity Console debug

Above is the basic example, but it is sure that if you are in programming with Unity for a long time, we will have to use Debug Log to output at some point of time. So how to use the debugging feature in Unity3D?

  1. For Debugging, click on the left edge of the line you want to debug in the editor(for example, if you want to debug your code on 7th line click the left edge of the editor besides 7th line), as soon as you click it, a red dot will appear there indicating that the debugging breakpoint is created.

  2. breakpoint in Unity IDE

  3. Now to start using the Debugger, all we need to do is just press the Play button on the top of Mono Develop window:

  4. Debug Button in Unity
  5. Once we press the Play button, Mono Develop will prompt us "Attach to a process". After that you have to select the instance of unity and press Attach.

  6. For Now, it will not do anything, but if we go to Unity and press Play button in the editor window then something will happen...

    Breakpoint in unity IDE
  7. Now, at the bottom of the window panel, there will be an option like "Locals", just click it (if you don't find "Locals" at the bottow of the window panel ,go to View->Debug Windows->Locals), you will see, every variables that are there in your code and their values at that the point of time.

  8. To continue the application execution, press Play button in Mono Develop.

  9. Play Button in Unity
  10. To stop Debugging, just press the "Stop" button on the top of Mono Develop window.

                 






Comments










Search Anything:

Sponsored Deals ends in





Technical Quizzes Specially For You:

Search Tags

    Debugging in Unity3D

    Tips for Unity3D Debugging