Effect of Parenting in Unity

Notes:

Effect of Parenting Game Objects in Unity:
Note: All root level game objects are placed, rotated & scaled relative to the global space, but
all child game objects are placed, rotated and scaled relative to their parent’s local space

W.K.T. Every game object comes with its own coordinate system (self, or local space).

On parenting:
1. An invisible link is created between parent and its child game object
2. A game object is shifted from its current space to its parent’s local space

Any modification done to the transform of a game object will affect to the transform of all its descendents / successors; it will not affect to the transform of its predecessors / ancestors.

Ex:
- Child game object’s position indicates the position offset relative its parent’s position
- If you shift a parent game object, then based on the position value of a parent game object all its descendents are going to be shifted.

- Child game object’s rotation indicates the rotation offset relative its parent’s rotation
- If you rotate a parent game object, then based on the rotation value of a parent game object all its descendents are going to be shifted and rotated

- Child game object’s scale indicates the scale relative to its parent’s scale.
- If you scale a parent game object then based on the scale value of a parent game object all its descendents are going to be shifted and scaled

Example Code:
using UnityEngine;

public class DrawLink : MonoBehaviour {

public Transform target;

void OnDrawGizmosSelected() {

if (target != null) {
Gizmos.color = Color.blue;
Gizmos.DrawLine(transform.position, target.position);
}

}

}