R
R
ReWire_922021-02-03 20:52:54
Unity
ReWire_92, 2021-02-03 20:52:54

How to access the topmost object in the gameobject hierarchy in Unity?

I shoot with raycast at one of the many colliders on objects that are in the attachments of the game object on which the script of the ColBehavior type hangs.
From the raycast script I get a link to the ColBehavior script via

behavior = shoot_ray.transform.GetComponentInParent<ColBehavior>();


Is there some way, when hitting any of the nested objects of the parent, immediately access the root itself, inside which everything is nested, bypassing the process of recursively enumerating one parent after another, until the root is reached?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question