Getting a transform's sibling at the root level where parent transform is null

Hi,

I’m trying to get the sibling transform of a transform when they are both at the root level and have no parent but I can’t seem to find a method to do this in the doc…

Since both transforms are at the topmost level of the hierarchy, their parent transform is null so I can’t call parent.GetChild(int idx) …

I’m probably missing something but I can’t seem to find how to do this.

It seems so simple too…

Any idea?

Since there is no parent, there is no “sibling” relationship. The best you can probably do is Get a reference to the scene and use this: Unity - Scripting API: SceneManagement.Scene.GetRootGameObjects to get an array of all the root objects. Then Analyze that array to find the objects next to the object you care about.

2 Likes