Composite Design Pattern in Unity, Redundant?

Hello, I’m an experienced programmer but new to Unity and C# trying to get some experience. I’ve been writing some code that could in some day be an RTS and I recently finished adding unit hierarchy ie. a group of soldiers:

- Company
  - Company HQ Platoon
       - Soldier
       - Soldier
     -Mortar Platoon

where each can be a single Mesh/GameObject ( a sniper ) a group of units ( platoon ) and they would know how to access their children, parent, siblings etc.

I did this using a custom Composite Design pattern when I realized that the “relatives” in GetComponentIn[Children|Parent] only refer to components on the local(right word?) GameObject and that the hierarchy in the Hierarchy Editor window doesn’t seem to persist to runtime.

Is this accurate? Am I missing something easy? Profiling my composite setup seems totally fast enough, if there is a built in Unity way to do this would it be faster than mine?

Thanks for any advice!

You’re correct that GetComponent refers to components attached to the same gameobject as the one on which the script is running, and GetComponentIn [Children|Parent] is relative to that gameobject.

However, not sure what you mean by the hierarchy “not persisting at runtime” - it does, and defines how the hierarchy is traversed using transform.FindChild, transform.Parent etc. For efficiency, you’d normally want to avoid traversing the tree too much though (and certainly avoid using Gameobject.Find to get an arbitrary member of the hierarchy) - instead caching a reference to other needed gameobjects once in the Start () method of your component.