Game Development
Editing with the Inspector
Learn to edit component values in the Inspector window.
Inspector window
The Inspector window displays all details of the item selected in the Hierarchy or Project panel. When a GameObject is selected, its name, tag, layer, and all attached components are listed here.
// Transform fields visible in Inspector:
// Position: (0, 0, 0)
// Rotation: (0, 0, 0)
// Scale: (1, 1, 1)
Developers can edit numerical values of components directly through these fields in the window.
Inspector fields and SerializeField
In your C# scripts, public variables automatically appear as editable fields in the Inspector window. To keep a variable private yet expose it in the Inspector, use the [SerializeField] attribute.
public float speed = 5.0f;
[SerializeField] private int health = 100;
This allows you to quickly test and balance gameplay mechanics from the Inspector without editing code.
Exercise Print Inspector field values
Define speed (value 5.5) and health (value 100) representing two Inspector fields. Print Speed: 5.5 | Health: 100 to the console.
Show example solution
using System;
class Program
{
static void Main()
{
double speed = 5.5;
int health = 100;
Console.WriteLine("Speed: " + speed + " | Health: " + health);
}
}
Test yourself
-
What happens to modifications made in the Inspector window while the game is running in Play mode?
- Unity automatically compiles the entire project from scratch.
- All components in the scene are instantly deleted.
- When exiting Play mode, values revert back to their pre-test state.
- Changes are permanently saved to disk and cannot be undone.
Show answer
When exiting Play mode, values revert back to their pre-test state. — Inspector modifications during Play mode are temporary; they revert to original values when playback stops.
-
Expose private variable to Inspector
[____] private float jumpForce = 8.5f;
Show answer
[SerializeField] private float jumpForce = 8.5f;
-
Inspector terms
- Inspector
- Panel editing selected object components
- SerializeField
- Shows private variables in the Inspector
- Transform Fields
- Position, rotation and scale input boxes
- Play Mode
- Runtime mode where values are tested
Next lesson: Tags and Layers