Why is there no gameObject.parent?

Is there any reason for this?..

It seems sort of confusing that the Transform component deals with hierarchy (parent, childCount, DetachChildren, etc), when it mostly deals with location/rotation/scale, and is a part of the gameObject (which is a container for components and child objects)

I know you can just do gameObject.transform.parent… but that can get annoying when you are storing variables and keeping track of objects and constantly have to switch between gameobject and transform references…

Does anyone know the reason for this? or at least why there is no built-in inherited version to make gameObject.parent work?

That’s a design decision unity made.

If you really want to have that functionality, here’s a class that will help you:

public static class ParentFinder
	public static Transform parent(this GameObject obj)
		return obj.transform.parent;

include the file ParentFinder.cs in any project you make, and now all gameObjects will have an accessible method called “parent” which will return the gameobject’s transform’s parent.

If you’re going to be doing a lot of this per frame (like flocking hundreds of objects or something), you’ll want to create a direct reference to the transform and the transform’s parent.