![]() |
VOOZH | about |
No matter how experienced you are, errors are a daily part of Unity development. A missing semicolon, a forgotten assignment or a typo can stop your game from running. Once you understand what that error message means, fixing them becomes easy. This article covers the most common Unity errors.
What it looks like:
NullReferenceException: Object reference not set to an instance of an object.
What it means: You tried to use something that doesn't exist. A variable is null (empty).
Common causes:
Example of the problem:
How to fix:
What it looks like:
MissingReferenceException: The object of type 'GameObject' has been destroyed.
What it means: The object existed before, but was destroyed. You're still trying to use it.
Example of the problem:
How to fix:
What it looks like:
IndexOutOfRangeException: Index was outside the bounds of the array.
What it means: You tried to access array position that doesn't exist. Example: array of size 5, but you tried position 10.
Example of the problem:
How to fix:
What it looks like:
Assets/Scripts/Player.cs(12,25): error CS1002: ; expected.
What it means: You forgot a semicolon ; at the end of a line.
Example of the problem:
How to fix: Add ; at the end of the line.
Most common places to forget:
What it looks like:
Assets/Scripts/Player.cs(15,13): error CS0103: The name 'healh' does not exist in the current context.
What it means: You typed a variable name wrong (typo). C# is case-sensitive.
Example of the problem:
How to fix: Check spelling. health vs healh. Player vs player.
Common typos: