- Home /
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.
Answer by tanoshimi · Mar 16, 2015 at 08:53 PM
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....
You need to $$anonymous$$ch them step debugging. I can't believe how little of that I did in High School / College and how much of it I do as a professional.
I've given them a debugging assignment already they just asked for a list of common errors and solutions to them as a sort of cheat sheet for when they have an error. The hope is to give them a starting place to look at that eventually they don't need after doing it enough. I will add a part for what to do when the sheet doesn't answer their particular error explaining the steps you said before.
Wait - just to be totally sure - you mean you gave them a step debugging assignment? Where you use a debugger (like the one in Visual Studio or NetBeans), attach it to a process, and step thru line-by-line? Or just one where they have to add print
calls all over the place? Because using the VS debugger is SO helpful.
Not trying to berate you or anything - just what I wish I had been taught as a student.
I didn't go through step debugging, sorry I read your comment wrong. I gave them an assignment in which I gave them a project in which many of the errors I'm writing above are in it. Teaching them step debugging would be a great thing to do though I'll try to fit it in somewhere.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
DontDestroyOnLoad make errors 0 Answers
The generic list blues (Argument out of range error) 1 Answer
Im getting this error CS0246 2 Answers
Removing items from a list while iterating through it? 3 Answers