Unity GameObjects and Components

Last Updated : 30 Apr, 2026

A GameObject is the basic building block of any Unity scene. It represents any object that exists in your game world.

  • A player character is a gameObject.
  • An enemy, a coin, a wall, a light source – all are gameObjects.
  • Even the camera is a gameObject.
Empty-gameobject-Unity
Gameobject in Unity

A GameObject is like an empty container. By itself, it does nothing. It has no shape, no color, no behavior. You add Components to give it these properties.

What is a Component?

A Component is a piece of functionality attached to a GameObject. Components bring GameObjects to life.

  • Add a Collider to detect collisions with other objects
  • Add a Script to control its behavior with custom code
components-in-unity-
Components in Unity

The Transform Component

Every GameObject in Unity has a Transform component. It cannot be removed.

  • Position: Defines the object’s location in the game world using X, Y, Z coordinates
  • Rotation: Defines the object’s orientation using X, Y, Z angles (in degrees)
  • Scale: Defines the object’s size along X, Y, Z axes (1 represents the original size)

Note: 2D games use RectTransform (similar but with additional 2D layout properties).

Adding Components to a GameObject

There are multiple ways to add components:

  • Select the GameObject in Hierarchy - Click Add Component in Inspector
  • Drag and drop a script onto the GameObject
  • Use the Component menu in the top toolbar
add-components-
Add Component in Unity

Common Built-in Components

ComponentPurpose
Mesh FilterDefines the shape (mesh) of the object
Mesh RendererDisplays the mesh with materials
Box / Sphere / Capsule ColliderDefines the collision shape of the object
RigidbodyAdds physics such as gravity, forces, and velocity
Audio SourcePlays sound effects or music
LightEmits light into the scene
CameraRenders what the player sees

Parent-Child Relationship

GameObjects can be nested under other gameObjects. This creates a hierarchy.

  • Parent – The main gameObject.
  • Child – Any gameObject placed under a parent.

When you move, rotate, or scale the parent, all children move with it.

parent--child-gameobject
Parent - Child Relationship in Unity

Common use cases:

  • Attach a weapon to a character's hand
  • Group multiple objects as one unit
  • Create doors with moving parts

Finding GameObjects in Scripts

To control a GameObject from code, you need to reference it:

C#
// Find by name (not recommended for performance)
GameObject enemy = GameObject.Find("Enemy");
// Get a component from the current GameObject
Rigidbody rb = GetComponent<Rigidbody>();
// Find the GameObject this script is attached to
gameObject.SetActive(false);  // Disables the GameObject

The first line searches the entire scene for a GameObject named "Enemy", avoid using this every frame as it hurts performance. The second line retrieves the Rigidbody component attached to the same GameObject, allowing you to modify physics properties like velocity or mass. The third line refers to the GameObject this script is attached to; calling SetActive(false) makes the entire object disappear from the scene.

Disabling GameObjects and Components

You can temporarily turn off GameObjects or individual components:

Disabling-GameObjects-and-Components
Disabling GameObjects and Components
  • Disable a GameObject – Uncheck the box next to its name in Hierarchy or Inspector
  • Disable a Component – Uncheck the box next to the component name in Inspector

Common Mistakes

  • Looking for a Sprite Renderer on a 3D object: 3D objects use Mesh Renderer, not Sprite Renderer
  • Adding two colliders of the same type: Unnecessary, a single collider is sufficient
  • Forgetting to add a Collider with Rigidbody: Object may fall through the ground without a collider
  • Disabling Transform component: Not possible, Transform is always present on every GameObject
Comment
Article Tags:

Explore