Null-Safe GetComponent Call in Unity
Objective: use the well-known GetComponent method in a new, null-safe way
In this tutorial, I’m going to show you a simple idea to avoid writing the same 2 lines of code over and over again.
Many times we use the GetComponent method to grab a reference to a Component attached to a game object, usually the same game object to which our script is attached.
For many reasons (inattention, dynamic stuff going on…), this method may return null, meaning that no component of the specific type wasfound.