I was programing Flappy Bird and the UnityEngine says: NullReferenceException: Object reference not set to an instance of an object
PipeMiddleScript.OnTriggerEnter2D (UnityEngine.Collider2D collision) (at Assets/PipeMiddleScript.cs:26)
Here is the script of PipeMiddleScript and LogicScript:
Identify what is null â any other action taken before this step is WASTED TIME
Identify why it is null
Fix that.
Expect to see this error a LOT. Itâs easily the most common thing to do when working. Learn how to fix it rapidly. Itâs easy. See the above link for more tips.
You need to figure out HOW that variable is supposed to get its initial value. There are many ways in Unity. In order of likelihood, it might be ONE of the following:
drag it in using the inspector
code inside this script initializes it
some OTHER external code initializes it
? something else?
This is the kind of mindset and thinking process you need to bring to this problem:
Step by step, break it down, find the problem.
Here is an analogy of a null reference:
I give you an empty cookie jar
I tell you to take a cookie from the jar
Your job is to identify which jar is empty, find out why it is empty, and fix that.