NullHunter: An Editor script that flags potential Null References

When giving Spamocalypse a test recently, I ran into an issue where I hadn’t initialised a variable, resulting in my console being filled with NullReferenceExceptions. This annoyed me enough that I went and wrote an Editor extension that looks for null public variables in a particular MonoBehaviour.

It’s based around reflection, which is the ability of a computer programme to examine itself. This allows you to do things like create mock objects for unit testing, examine the fields of a class, or even change a private variable or method to public! This is something I’ve never done before, but it only took me a few hours of reading the MSDN docs and a quick check on the Unity forums when I ran into an ArgumentException before I was able to make a basic version.

You can find it on GitHub. I’ve decided to release it under an MIT licence; so you just need to attribute it to me if you use it yourself, but there are no restrictions on how you use it.

Update: I’ve created <a href=””>a video demo</a>.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.