In my Player script, I initialize my FirePoint transform using GameObject.Find in the Awake function. In the editor, I purposely misspelled the name of FirePoint to test if the null check inside of my Fire function will print an error to the console. The only error that shows up is from the Awake function giving a NullReferenceException, but why don't I see my Debug.LogError? Instead, the else statement prints that the FirePoint is not null.
public class Player : MonoBehaviour
{
[HideInInspector] public Transform FirePoint;
private void Awake()
{
FirePoint = GameObject.Find("FirePoint").transform;
}
private void Fire()
{
if (FirePoint == null)
{
Debug.LogError("FirePoint is null.");
}
else
{
print("FirePoint is NOT null.");
}
}
}