Hierarchy and Transforms
↑How it works and why
Section titled “How it works and why”The Hierarchy shows the objects in the loaded scenes. A parent-child relationship makes child transforms relative to the parent. transform.position is in world coordinates; transform.localPosition is relative to its parent. Rotations follow a similar distinction. A nested child inherits the parent’s movement and rotation, and often scale, which can create surprising physics behavior.
Group related objects under deliberate parents (for example Player > Model > WeaponMount), but avoid huge deeply nested hierarchies just for visual tidiness.
Example you can try
Section titled “Example you can try”using UnityEngine;
public sealed class FollowParent : MonoBehaviour{ [SerializeField] private Transform target;
private void LateUpdate() { if (target == null) return; transform.position = target.position + Vector3.up * 2f; }}When to use it and what can go wrong
Section titled “When to use it and what can go wrong”Why LateUpdate? It runs after normal Update methods, making it suitable for many follow-camera adjustments. Pitfall: Calling SetParent(parent, false) keeps local transform coordinates; SetParent(parent, true) attempts to preserve world space.
Try it: Parent a cube under a rotated object and compare position with localPosition in the Inspector and Debug.Log.
