Hierarchy

Introduction to Unity Hierarchy

The Hierarchy window in Unity shows a list of all GameObjects in the current scene. Each GameObject in the Hierarchy represents an object in the game world, such as cameras, lights, and characters. Organizing objects in the Hierarchy helps manage and control different parts of your game.
// Creating a new GameObject and adding it to the hierarchy GameObject newObject = new GameObject("MyNewObject");

Scene Main

The Scene window is where you visually lay out your game objects. It acts like a canvas where you can position, rotate, and scale objects to set up your game world. This view provides tools for creating and arranging elements and a preview of how objects will appear during gameplay.
// Moving an object in the scene newObject.transform.position = new Vector3(0, 1, 0);

Main Camera - Lens Settings

The Main Camera in Unity acts as the viewpoint through which players see the game world. You can adjust the Lens settings, such as Field of View (FOV), to control how much of the scene is visible. Other settings like Clipping Planes define the minimum and maximum distances at which objects are visible.
// Accessing and modifying the main camera's lens settings Camera.main.fieldOfView = 60; Camera.main.nearClipPlane = 0.1f; Camera.main.farClipPlane = 1000f;
Note: You can also adjust the Main Camera manually through the Inspector side

Directional Light

Directional Light is a type of light that mimics sunlight, casting parallel rays across the scene. It’s useful for outdoor scenes and provides even lighting. Adjusting settings like Intensity and Color changes the brightness and tone of the lighting, affecting the mood of the scene.
// Creating a directional light and setting its properties GameObject lightGameObject = new GameObject("Directional Light"); Light lightComp = lightGameObject.AddComponent<Light>(); lightComp.type = LightType.Directional; lightComp.color = Color.white; lightComp.intensity = 1.0f;
Note: You can also adjust the Directional Light manually through the Inspector side

Parent-Child Relationships

In Unity, you can organize GameObjects in a parent-child hierarchy. A Parent object can control its Child objects' position, rotation, and scale. For example, if a parent object moves, all its child objects move with it. This setup is helpful for creating groups of objects that need to stay together, like a character holding a weapon.
// Setting a child object under a parent object GameObject childObject = new GameObject("ChildObject"); childObject.transform.parent = newObject.transform; // Setting newObject as the parent

Example Set-Up

notion image
This Unity interface highlights elements within the "Hierarchy" panel, showcasing the foundational structure of a scene setup. The scene, named "SampleScene," contains essential objects:
  1. Main Camera: This object serves as the "lens" through which the game view is rendered. It determines what the player sees and controls aspects like field of view, clipping planes, and depth.
  1. Directional Light: Positioned as a global light source, this object simulates sunlight and casts uniform light across the scene, contributing to shadows and overall illumination.
  1. Demo: This custom object appears as an independent element, with no visible parent or child objects, suggesting a simple hierarchy for this initial setup. The "Demo" object has an associated script component in the "Inspector" panel, indicating it may act as a data manager or controller.
In Unity, a parent-child hierarchy allows objects to inherit transformations and properties from their parent objects, which is particularly useful for organizing complex scenes and creating cohesive object groups. Here, however, the setup is straightforward, without nested (child) objects, which keeps the hierarchy flat and uncluttered for easier management during early development stages.