- Home /
How to inspect non-MonoBehaviour classes in the debugger
My problem is that I can't inspect classes that don't derive from MonoBehaviour in MonoDevelop during debugging.
From what I could gather, from Google and this place, about Unity-debugging is that your only option is to use MonoDevelop. Now, if you want to use NUnit as a unit testing framework you can't use it to test classes that derive from MonoBehaviour. On the other hand MonoDevelop doesn't show any debug info for classes that don't derive from MonoBehaviour. The variable inspector simply states something like "reference not set to an instance of an object" (the actual message I get is in German). This is similar to what you get often times when a script references a missing Component and the like. But the instance does exist, I can even step into the code if I call a public method on the instance. What I tried, to no avail, is setting the "Active Configuration" of MonoDevelop to either Release or Debug (get debug info for MonoBehaviour classes for both settings but none otherwise). I tried setting the [System.Serializable] attribute for the class. I even tried out what happens if I stupidly set all accessor modifiers to public - defying everything we know about OOP. Nothing.
I know the workarounds: Put variables into MonoBehaviour classes that copy the properties you want to expect. Meh. Or make extensive use of Debug.Log. Meh. That's only giving a crutch to a man that could walk perfectly fine, if he knew how.
I will stick to SharpUnit for the testing, though I will have to tweak the error reporting a bit to fit for the Jenkins CI server I use. I would still rather use NUnit and basically it's not a good idea to have every class derive from MonoBehaviour just to make it debuggable.
Edit/Update: I dabbled a bit with the MonoDevelop you get via mono-project.com. It does debugging just fine, but lacks the Unity-Addins. Also the version that comes with Unity seems to be simplified, at least as far as the UI goes. I didn't figure out how to run the project with an other debugger than Unity-Debugger. Oh, maybe I should try to contact Lucas Meijer who is named as the author of the Unity-Debugger-Addin for MonoDevelop. Judging by the two up votes so far, I'm not the only one to have an interest in settling this matter :-)
Update2: Lucas suggested I should file a bug report. Did do. Let's see what happens.
$$anonymous$$onoDevelop lets you inspect any type of variable, not just components. While it's true that NUnit, as integrated with $$anonymous$$onoDevelop, doesn't play nicely with Unity, it is possible to write your own NUnit integration for Unity -- basically you need to write at test runner that uses the core NUnit framework but implements its UI in Unity. You could also check the Unity Asset Store for unit testing frameworks.
Lucas is right it must be a bug. It used to work fine until not so long ago. Also things like the List inspector broke a couple of updates ago.
Answer by unimechanic · Jul 14, 2014 at 01:24 PM
This should work currently, otherwise please submit a bug report: