How can I get a parent GameObject of gameObject using Javascript?

I have grouped few GameObject into one GameObject. Is it possible to get the parent `GameObject` if you know the child `GameObject` using Javascript?

Something similar to the `transform.parent`.

childObject.transform.parent.gameObject

Thanks hahaha finally this power is miiiiine!

1 Like

Gameobject obj = this.transform.parent;

with the help of this code you can get the parent of the current gameobject to which script is attached

Perfect. And for those that have multiple sub-children, just duplicate transform.parent.gameobject

In this example, there’s 2 subchildren. So to acquire the top parent I had to duplicate.

parent (gameobject)
→ child (gameobject)
—> child (gameobject)

gameObject.transform.parent.gameObject.transform.parent.gameObject

Sharing is Caring

https://twitter.com/IndieNendoroid

transform.root.gameObject gives you the Genitor!

Debug.Log(gameObjectYouWantTheParentOf.transform.parent.name);

function OnTriggerEnter (other :Collider)
{
other.transform.parent
= gameObject.transform; } function OnTriggerExit (other :
Collider) { other.transform.parent
= null; }

Here you go Full script. just attach this script to your emptyObject with triggered collider on it. but make sure the empty object is a child of the cube/platform who has the animation on it and this script goes to that child. and done. the character looks squeezed but if you have any solution please provide me one and i am working on it aswell.