I am checking to see if "My Game Object" has a Rigidbody. It does not. But the conditional for the null check on Rigidbody fails, despite having just been proven null.
Why is this happening? How can I make my condition block run?
using UnityEngine;
using System.Collections;
public class NullChecker : MonoBehaviour
{
void Start()
{
GameObject go = GameObject.Find("My Game Object");
CheckIfNull<Rigidbody>(go);
}
public void CheckIfNull<ComponentType>(GameObject gameObject)
{
ComponentType component = gameObject.GetComponent<ComponentType>();
Debug.Log("Component is " + component); //"Component is null"
if (component == null)
{
Debug.Log("Inside null check"); //Never prints
}
Debug.Log("Finished null check"); //Does print
}
}