Unity Common Errors, List of Common problems and Common Solutions

Hey I’m making a list of the most common errors I see and the common solutions to them. I’m really looking to expand this list and give it to my students to look at and so they have a place to look at when they have all these errors that will make the rest of us cringe when they ask us to fix it. Anyways here’s what I made up in a few minutes and I’ll be editing with any suggestions or as I remember more so any suggestions are appreciated.

Problem: No errors but nothing is happening

-Check if Monobehaviour is attached to gameObject
-Make sure unity methods(Start, Update) are spelled properly

Problem: Null reference error at runtime

-Check if any object fields(Transform, GameObject, Monobehaviour) have nothing dragged into them.
-IF you are using GetComponent calls make sure your gameObject actually has that component on it, also use [RequireComponent(Type)] if you do use this to assign variables at runtime

Problem: Can’t Drag Monobehaviour onto gameObject

-Check that the file name and the class name is the same
-Make sure the script it has no compiler errors

Problem: General Errors

-Semi-Colons, make sure they’re there
-Does every (),{},,” ”,< > have it’s pair?

When This Doesn’t Work
-Look at the Error Message, what does it say? Does it make sense?
-Look at the line number(the first number in parentheses), this is where the error occurred
-Look at the line above the error, it could also be the cause
-Search the Error message on Google, Add in a “Unity” or “C#” or any keywords about what you are doing if the results aren’t specific enough
-If all else fails go to Unity Answers forums and ask the question, make sure to include your code and specific details about the error and which line it occurs on, the more specific it is the more likely some one can help you or you will figure it out yourself.

While I’m sure your intentions are good, I have to disagree with the pedagogy of your approach. IMO, if you want to provide something to help your students overcome programming errors they make, there are 3 things you should do for them; namely, teach them:

  • how to understand an error message: it will generally tell you the script and line in which the error occurred, a description of the problem and, on many occasions, suggestions to fix it.
  • how to search for information about those errors on the internet.
  • if, after searching, they can’t find the solution for their errors, teach them how to write a well-formed question on a site such as Unity Answers or StackExchange; what information is relevant to include and what isn’t, what steps are required to reproduce, etc.

That will help fix any error they encounter in the future…