Is there a type which can refer to both GameObject and MonoBehaviour?

Or a way to trick one into existence?

I have this function (consider {} to be > and <):

public static void ProjectPicker{T}( ref T cur, Validator{T} validate ) where T : Component {

It builds a graphical interface to pick an object of type T from objects in the project (since Unity’s ObjectField doesn’t do any filtering at all).

I use the objects’ parenting to sort them into folders, and as far as I know transform.parent is the only way to get the parent (right?). SO I need .transform, which both Component and MonoBehaviour have, but their parent (Object) does not.

Is there a way to write a single function that can accept both Component and MB as its T type and still access their .transform, or is there something I can do to write an override function of the other type and somehow call the original function (I’ll do literally anything to not duplicate the function, including simply not support GameObjects at all), or is there another way to read an object’s folder structure?

I’d like a single function, but if there’s one like this I’d be fine:

public static void ProjectPicker( ref GameObject cur, Validator{GameObject} validate ) {
  Component temp = ???;
  ProjectPicker( ref temp, validate );
  cur = (GameObject?)temp;

Transform is a Component, and every GameObject is guaranteed to have a Transform, so you can use Transform as your T type when you need to find every GameObject.