The Wrong Null!

tl;dr:

  • You can check whether a Unity.Object (including Component, GameObject, MonoBehaviour, etc.) is null using if (variableName), because it has an implicit bool operator that checks != null.
  • If you’re trying to expose generic-typed properties in the inspector, you should constrain them with where T : Component or similar, or strange things may happen when you check whether they’re assigned.
  • I probably shouldn’t rely on generics so much. It’ll haunt me if I ever need to build for mobile or console.

Continue reading The Wrong Null!

Beginner Unity Script Troubleshooting

Between mentoring game jams and working on my own stuff, I’ve ended up with a list of basic Unity scripting pitfalls, many of which don’t cause runtime exceptions or log any errors. I emphasise that most of these areĀ really basic, and anyone who spends a while with the platform will internalise them sooner or later, but if they’re not yet obvious to you, I hope you find the list useful.

Continue reading Beginner Unity Script Troubleshooting