In Unity, everything that exists in a scene is a GameObject. But a GameObject by itself is an empty box. All functionality is given to it by Components. Understanding this difference is the key to flexible, confusion-free architecture.
- A name (
name) - An active state (
activeSelf/SetActive()) - Position, rotation, scale (via the mandatory
Transformcomponent) - A list of attached components
🧠 Think of a GameObject as an empty plastic box with a name sticker. The box itself does nothing.
- Empty object (
Create Empty) - Cube, sphere, capsule (actually GameObject +
MeshFilter+MeshRenderercomponents) - Character, wall, light source, camera
- Cannot exist on its own (always attached to a GameObject)
- Gives the object concrete properties: physics, visuals, sound, logic
- Can be removed, added, or temporarily disabled
🧠 Think of components as tools you put inside the box: an engine (Rigidbody), paint (MeshRenderer), a microphone (AudioSource), a brain (your script).
Transform(exists on every GameObject, cannot be removed)MeshRenderer— to make the object visibleRigidbody— to apply gravity and physicsAudioSource— to play sound- Your own script
PlayerHealth.cs— to store health and react to damage
| Feature | GameObject | Component |
|---|---|---|
| Essence | Container | Behavior / Data |
| Can exist alone? | ✅ Yes | ❌ No (only inside a GameObject) |
| Added / removed | Create/destroy object | ✅ Can be added and removed |
| Example | "Character", "Door" | "Movement script", "Collider" |
Hierarchy → Right-click → Create Empty → name it Enemy
Select Enemy → click Add Component:
Mesh Filter→ choose a mesh (e.g., sphere)Mesh Renderer→ assign a material (color)Capsule Collider→ to enable collisionsRigidbody→ so it falls under gravity- Your script
EnemyAI(write it) → to make the enemy move toward the player
Uncheck Rigidbody in the Inspector → gravity disappears.
Uncheck Mesh Renderer → the enemy becomes invisible (but still runs its logic).
❌ "My script cannot see the Speed variable of another object"
✅ You need to understand: the variable is not inside the GameObject, but inside a specific component (e.g., PlayerMovement). Access it like this:
GameObject player = GameObject.Find("Player");
PlayerMovement movement = player.GetComponent<PlayerMovement>();
float speed = movement.speed;The GameObject defines WHAT exists. The Component defines WHAT IT DOES and HOW IT LOOKS.