Editing Get Component

Hi, I’d like to edit get component from
“GameObject.Find(“Name”).GetComponent();”

to

“UtilitiesGameObject.FindObjectGetComponent (String Name, Class Param)”

I’m trying to write a generic like so:

public static T FindObjectGetComponent<T> (string name, T param) 
    {
        GameObject.Find(name).GetComponent<**param**>();
    }

param isn’t working. I can’t figure out how to pass the generic in.

Please assist.

You probably want to do something like:

public static T FindObjectGetComponent<T> (string name) where T : Component
{
    GameObject obj = GameObject.Find(name);
    if (obj == null)
        return null;
    return obj.GetComponent<T>();
}

The null check is important to aviod a null-reference exception inside your helper when there is no GameObject with that name.