Skip to main content
Unity 3D Basics – Complete Beginner to Advanced Guide
CHAPTER 03 Beginner

GameObjects and Components

Updated: May 16, 2026
20 min read

# CHAPTER 3

GameObjects and Components

1. Introduction

At the heart of Unity lies a brilliantly simple architectural concept: everything in your game is essentially an empty container waiting to be filled with features. Whether you are creating a blazing sun, an invisible trigger zone, a complex player character, or an enemy zombie, you start with the exact same base entity. In this chapter, we will master Unity's core architecture: GameObjects and Components. We will explore the critical Transform component, understand Parent-Child relationships, and learn how to save and duplicate complex objects using Prefabs.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Define the relationship between a GameObject and a Component.
  • Understand the role of the Transform component (Position, Rotation, Scale).
  • Create Parent-Child hierarchies in the editor.
  • Utilize Tags and Layers to categorize game entities.
  • Create, modify, and instantiate Prefabs.

3. The GameObject (The Empty Container)

A GameObject is the fundamental object in Unity. By itself, a GameObject does absolutely nothing. It is invisible, has no physics, and makes no sound. It is simply an empty container.
  • If you look in your Hierarchy, *every single item* on that list is a GameObject. The Main Camera is a GameObject. The Directional Light is a GameObject.

4. Components (The Lego Blocks)

If a GameObject is an empty container, Components are the Lego blocks you drop inside to give it functionality. You view an object's Components by clicking the object and looking at the Inspector.
  • Mesh Filter + Mesh Renderer: Makes the object visible as a 3D model.
  • Light: Makes the object emit light.
  • Audio Source: Makes the object play a sound.
  • Rigidbody: Gives the object mass and gravity.
*A "Player" is simply a GameObject that contains a 3D Mesh, a Rigidbody, an Audio Source for footsteps, and a custom C# script Component!*

5. The Transform Component

There is one exception to the "empty container" rule. *Every* GameObject must have exactly one Component that cannot be deleted: the Transform. The Transform defines where the object exists in 3D space. It holds three properties:
  • Position: X, Y, Z coordinates.
  • Rotation: X, Y, Z angles in degrees.
  • Scale: X, Y, Z size multipliers (1 is default size).

6. Parent-Child Hierarchies

In the Hierarchy panel, you can drag one GameObject onto another to make it a "Child."
  • If you make a "Sword" a child of a "Player," the Sword's Transform is now *relative* to the Player.
  • If the Player moves forward 10 meters, the Sword automatically moves forward 10 meters. If the Player rotates, the Sword rotates with them.

7. Tags and Layers

At the very top of the Inspector, you will see two dropdowns:
  • Tag: A text label used to quickly identify objects in C# code. (e.g., tagging your hero as "Player" so enemies know who to attack).
  • Layer: Used to group objects for rendering and physics. (e.g., putting all walls on a "Wall" layer, and telling the camera not to render the "Wall" layer).

8. Prefabs (Saving for Later)

If you spend 20 minutes attaching lights, rigidbodies, and scripts to an Enemy GameObject, you don't want to do that 50 more times to make a horde.
  • You can drag a GameObject from the Hierarchy directly into your Project Window (the bottom panel).
  • This turns the GameObject into a Prefab (represented by a blue cube icon).
  • A Prefab is a saved master template of an object. You can now drag that Prefab into your scene 50 times. If you decide the enemy needs more health, you open the Prefab, change the health once, and *all 50 enemies in your game update instantly!*

9. Visual Learning: The Component System

txt
12345678
GameObject: "Alien_Enemy"
+---------------------------------------+
|  [ Transform ]                        | <-- Where it is
|  [ Skinned Mesh Renderer ]            | <-- What it looks like
|  [ Capsule Collider ]                 | <-- Its physical hit-box
|  [ Audio Source ]                     | <-- Its growl sound
|  [ EnemyAI.cs ] (Your Custom Script)  | <-- Its brain
+---------------------------------------+

10. Best Practices

  • Reset Transforms: When creating an empty GameObject to act as a folder/parent for other objects, always click the three tiny dots on the Transform component in the Inspector and select Reset. This ensures the parent starts exactly at (0,0,0). If your parent is at a random position, moving its children later becomes a mathematical nightmare.

11. Common Mistakes

  • Unpacking Prefabs Accidentally: If you right-click a Prefab in the Hierarchy and select "Prefab -> Unpack Completely", it breaks the link to the master template. If you update the master template later, this unpacked object will not receive the updates. Only unpack a prefab if you intend to make it a completely unique, standalone object.

12. Mini Project: Build a Prefab

Objective: Create a complex object and turn it into a reusable Prefab.
  1. 1. Right-click the Hierarchy -> Create Empty. Name it "MagicCoin".
  1. 2. Right-click "MagicCoin" -> 3D Object -> Cylinder. This makes the visual cylinder a child of the empty container.
  1. 3. Select the Cylinder child, and change its Scale to X:1, Y:0.1, Z:1 (making it flat like a coin) and rotate it 90 on the Z axis.
  1. 4. Select the "MagicCoin" parent. Click Add Component -> Audio Source.
  1. 5. Now, drag the "MagicCoin" parent from the Hierarchy down into the Project Window.
  1. 6. The icon turns blue. You have created a Prefab! Drag 5 more coins from the Project Window into your scene.

13. Practice Exercises

  1. 1. What is the only component that is absolutely required on every single GameObject in Unity?
  1. 2. If you want to make an armor helmet stick perfectly to a character's head as they run around, what Hierarchy technique must you use?

14. MCQs with Answers

Question 1

In Unity's architecture, what provides a GameObject with its visual appearance, physics, and logic?

Question 2

You have placed 100 identical trees in your forest level. You realize the trees are too small. What is the most efficient way to resize all 100 trees simultaneously?

15. Interview Questions

  • Q: Explain Unity's "Entity-Component" architecture. How does it differ from traditional deep object-oriented inheritance?
  • Q: Describe the relationship between a Parent GameObject and a Child GameObject. How does moving or scaling the Parent affect the Child's Transform data?
  • Q: What is a Prefab in Unity? Explain the workflow benefits of using Prefabs when designing a level with recurring elements like enemies or power-ups.

16. FAQs

Q: Can I attach a C# script to an object as a Component? A: Yes! That is exactly how Unity works. Every C# script you write (that inherits from MonoBehaviour) is simply a custom Component that you drag and drop onto a GameObject.

17. Summary

In Chapter 3, we uncovered the DNA of a Unity project. We learned that GameObjects are empty containers, and we build functionality by attaching Lego-like Components (Audio, Physics, Rendering). We explored the omnipresent Transform component and utilized Parent-Child hierarchies to group objects together. Finally, we learned the immense time-saving power of Prefabs, allowing us to create master templates and deploy them across our entire game.

18. Next Chapter Recommendation

We have empty containers, but our world is quite gray. Let's make it look like a real game. Proceed to Chapter 4: Working with 3D Objects and Environments.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·