Beginner mistakes to avoid in Unity

Learning a new skill always requires you to make mistakes. But to learn it quickly you need to correct those mistakes and make sure they are not repeated. Unity is very powerful tool but often beginners find themselves making the same mistakes. Here are a few beginners’ mistakes to avoid in Unity.

Beginner mistakes banner

Mind the spelling of predefined functions

Unity has many pre-defined functions like Start and Awake. Unlike Start and Update, other functions are not added by default to your code. New Unity developers often get the capital letter wrong

Start() is not the same function as start()

Don’t be shy to look up the Unity document to see the correct spelling of the function you are going to use.

Another common misspelled function is OnCollisionEnter(), remember the O,C and E are in capital letters.

The problem with this mistake is you will never see an error and it will be difficult to find out why your code is not working.

Two Non physics object cannot collide

Ever wonder why your OnCollisionEnter() function is not working even if the code is right?

That’s because two non-physics object’s collision is not detected by Unity.

You need to add a Rigidbody component to atleast one gameobject for the collision to be detected.

Your collision Bible

Rigidbody collider matrix

Null reference error

Most beginners follow some tutorial and copy the code exactly and run the game only to see a Null reference error.

This happens when your script is referencing a gameobject that is not assigned.

You must have added a code like this

public GameObject player;

After this you need to drag and drop the player to the script in the inspector window. If you forget that, you will get a null reference error.

drag and drop in Unity

Looking for errors

Most beginner try to look for errors inside the code editor. You need to understand that the code editor can only show you errors related to syntax.

Unity editor’s console window shows more details on what is wrong with your code. The best way to find the errors is to save the code and go to Unity editor’s console window.

Unity console window

If you are having a runtime error and not able to figure out why things are not working use code breaks and Debug.Log statement to identify the mistakes.

Awake works even if the script is disables

Yes, you read it right. The Awake function of your script will be called even if the script component is disabled in your gameobject.

You need to keep this in mind before you use the Awake function.

When you reference or assign some static variable in Awake it might create a problem that will be difficult to diagnose.

Leave a Reply

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