Go to Top

Struggling with the bugs? This tutorial will give you the knowledge to significantly improve your productivity by easily using MonoDevelop's powerful debugger to squash them quickly...

Motivation

You should read and watch this tutorial if you want to know how to exploit the very powerful debugging features of MonoDevelop:

  • How to be debugging in seconds without a rebuild
  • How to inspect the call stack
  • How to watch and change the values of variables

Debugging With MonoDevelop

First and most important you don't need to build your project and run it in order to debug.  Many people, myself included, don't know this and spend hours building with MonoDevelop and starting the Unity Editor through it to debug their game.  Don't do that.

Generally don't build your game using MonoDevelop.  The version of Mono that it builds to can be different to the version that Unity uses and it doesn't have all of the features or the #defines made!

The most notable missing feature can be optional parameters which are very powerful and work fine in Unity - but were for a long time not available in the version of Mono that MonoDevelop was building to.  Optional parameters have been available in Unity for a long time (since version 3.1 at least).  You might have to turn off building with MonoDevelop in Unity.  In MonoDevelop:  Preferences > Unity > Debugger and turn off "Build project in MonoDevelop".

Write your code in MonoDevelop - save it and let Unity do the build - it's far better this way.

To debug your code simply use the Run->Attach To Process menu in MonoDevelop and choose the Unity Editor.

Once you've done that you can set break points or break on exceptions in your code - then you can see and change all of the variables with the watch window.

Debugging Lock Ups

Sometimes your code locks up - here's a classic example of this kind of bug:

IEnumerator SomeCoroutine()
{
      yield return new WaitForSeconds(2);
      while(Input.GetKeyDown(KeyCode.Space))
      {
           transform.position += transform.forward * Time.deltaTime;
      }
}

If you were pressing the space button when this code executed the while loop then everything will freeze with no chance of it returning or being stopped in the Unity Editor (we forgot to yield).

If your game locks up like this then attach the debugger as shown above and just click on Run -> Pause, then the call stack will show you where your problem is.

Video

The video is worth watching because there are a lot of tricks it's easier to show than write about.  So take a look and massively improve your productivity!

, , , ,

7 Responses to "Debugging Your Game with MonoDevelop"

  • Syntinel
    November 13, 2012 - 4:10 pm Reply

    Awesome video! Great quality and extremely informative. Thanks much.

  • MicroEyes
    November 17, 2012 - 8:03 am Reply

    Awesome Tut. Thanks. it really helps.

  • AkhmadMax
    April 25, 2013 - 7:54 am Reply

    I always wanted this functionality, but I didn’t even know that it is possible.
    Can we debug applications in the VisualStudio this way?

      • whydoidoit
        April 25, 2013 - 8:59 am Reply

        Yes I use that. It’s pretty good!

  • cesarpo
    June 28, 2013 - 1:04 am Reply

    Thank you! You relieved me part of the monodevelop-unity suckiness!

  • rajat
    July 18, 2013 - 10:30 am Reply

    Thanks a lot matey!
    I used monodevelop like a text editor with auto-complete and never realized that mono-develop is as good as visual studio.

Leave a Reply