I keep getting hung up on how objects are related in Unity. I understand what each of them is, but not how they’re related.:-?
Is there a diagram or some other documentation somewhere about how these are related to help me get my head around this?:!: I keep getting it wrong, and a picture might help.
Every GameObject has one or more Components attached (always at least a Transform Component). When you select a GameObjectd in the Hierarchy View, its Components are listed in the Inspector as they are now part of the GameObject. In addition, a GameObject can also have other GameObjects as children, which is what you see in the Hierarchy View (and you only see GameObjects in the Hierarchy View).
Technically, the parenting of GameObjects is through the Transform Component, but I find it conceptually simpler just to ignore that, except when scripting.
Maybe it’s easier, but I try to AM scripting and I NEED to know those silly details, that’s why it’s getting so confusing and I was asking for a picture ;). An ACCURATE picture, not the simplified one they show in the Unity IDE.
If I’m in a script attached to GameObject hand, how do I find the torso (arm) and fingers(children)?
I’m not going to draw a picture, but check out the documentation on Transform in the Scripting Reference. It has a an example of how to loop through the children of a Transform.
Think of GameObject as anything in your game scene. Car, Cube, Player.
Think of children as parts of your GameObject. Ie. A car has wheels, engine, seat, etc.
You probably dont really need to understand the concept of component. Everything in the game is a component. collider, rigidbody, scripts, transform
To be in the scene, your gameobject needs a location and a rotation. This is the Transform. Everything in your game needs a transform so that it knows where it is supposed to be located.