The Inspector window allows us to view and edit
the properties and settings of GameObjects and assets
as well as other preferences and settings in the Unity Editor.
When we select a GameObject
in the Hierarchy window or Scene view,
or an asset in the Project window,
the Inspector window will display all of the properties,
Components, and Materials on that GameObject or asset.
Depending upon what we select,
the Inspector will display different information.
Inspecting a setting such as the Player Settings
will look different from inspecting an asset
such as a model or texture.
One of the most common items to inspect is a GameObject,
either from our current Scene
or a GameObject Prefab asset from our project.
GameObjects are essentially containers for Components,
which drive the behavior of our GameObjects.
When inspecting a GameObject,
the top-most section displays information
about the GameObject itself.
Below that, the Inspector displays details about the Components
attached to the GameObject.
It is worth noting that every GameObject
must have a Transform Component attached, so every GameObject,
even an empty GameObject,
will display a header and a Transform.
The first part of the GameObject’s header bar
contains a Select Icon button for the selected GameObject.
The Select Icon button allows us to change the way
that a GameObject is displayed in the Scene view.
We can also assign a custom icon from any texture
in our assets folder by clicking the Other button
and selecting our desired icon.
Next to the GameObject’s icon button is a checkbox.
This checkbox allows us to toggle
whether or not the GameObject is active in the Scene.
When a GameObject is active,
all of the enabled Components on the GameObject
will be processed while the game is running.
When the GameObject is deactivated,
all of the enabled Components and custom scripts
attached to that GameObject will be ignored.
This includes Components which render or display
the GameObject in the Scene.
So when the GameObject is inactive,
it is turned off or hidden in the Scene.
It is also worth noting that when a GameObject is deactivated,
its name is also grayed out within the Hierarchy window.
In many cases,
individual Components attached to the GameObject
can be toggled on and off
by enabling or disabling the Component.
We will discuss this later in the lesson.
The next item in the header bar
is the Name field for the GameObject.
The Name field allows us to easily name
and identify the GameObjects in our Scene.
The Static toggle is used to define
whether or not a GameObject is static
and should be considered as a candidate
for processes such as Lightmapping,
Navigation Mesh Calculations, Occlusion Culling,
or other specific cases.
Static flags can be set individually
for specific processes if necessary.
For more information on the Static flag
and which processes use them,
please see the information link below.
Underneath the Name field, the header bar also contains
the Tag and Layer dropdown menus.
The Tag dropdown menu allows us to assign a tag to the GameObject.
This tag helps us identify a GameObject
or group of GameObjects for reference in our scripts
or to help us when performing a search.
The Layer dropdown menu allows us to assign our GameObjects
to a specific layer within the editor.
Layers are useful as we can assign special rules to specific layers
such as lighting, rendering, or collision rules,
and change the way that any GameObjects
in these layers behave in our Scene.
It is worth noting that these layers
are abstract groups of related GameObjects,
and these layers are not physically arranged in the Scene in any way.
For more information on tags and layers, and how to use them,
please see the information linked below.
If the GameObject is a Prefab instance,
the header bar will display the Prefab buttons.
The Prefab buttons allow us to select and locate
our original Prefab asset in the Project window,
revert any changes of the current Prefab instance
back to the state of the original Prefab asset,
or apply any changes made to the current instance of the Prefab
onto our original Prefab asset,
and across any other instances of the Prefab asset
that are in our project.
For more information on Prefabs and how to use them,
please see the information linked below.
Below the header bar are a list of all of the Components
attached to the GameObject.
We can use the Inspector to edit the properties and settings
of our GameObject’s Components.
Properties are specific values or references
to other objects or assets.
Values in the Inspector are represented by text boxes,
checkboxes, and menus, depending on their type.
It is worth noting that as well as entering a value into the field,
numeric text boxes can be changed by clicking
and dragging up or down over the property name.
Numeric text boxes can also resolve simple mathematical formula.
References are Component properties
that link to other objects and assets.
To assign a reference in the Inspector window,
we can simply click the small Select icon
to the right of the property.
This will open the Object Picker.
The Object Picker lets us search for
and select GameObjects and assets within a Scene or project
that match our selected property type.
We can also assign reference properties
by dragging an asset or GameObject
from the Scene view, Hierarchy window, or Project window
onto the reference property in the Inspector window.
When dragging a GameObject,
if the selected GameObject contains a Component
that matches the reference property type,
Unity will assign the appropriate Component
to the matching reference.
If a matching Component type cannot be found on the GameObject,
it will be rejected.
This makes it very easy to assign references
by simply dragging the GameObject itself into the reference
rather than the individual Components.
The Inspector window can also be used to easily find assets
and GameObjects that are being referenced.
Clicking on an assigned reference property
will reveal the location of the assigned GameObject or asset
in the Project or Hierarchy window.
The Inspector window also allows us
to change the values of multiple GameObjects at the same time.
When we have two or more GameObjects selected,
most Components that our selected GameObjects
have in common can be edited.
If the property values
of all the selected GameObjects are the same,
the value will be shown in the Property field.
If the property value is different between the selected GameObjects,
a " - " will be displayed instead.
If we change the value of any of the shared Components
in the Inspector window,
the value will be copied to all of our currently selected GameObjects.
We can easily view the documentation for most Components
directly from the Inspector.
Clicking the blue book icon
will open the documentation page for that Component
and allow us to find more information
about how to use the selected Component.
As there are actions
that can change the focus of the Inspector window,
we can lock the Inspector window at any time
by clicking the small padlock icon in the top-right
of the Inspector window.
This would lock the focus on the currently selected item.
This can be useful if we wish to keep an Inspector window open
while we are working on other items.
It is also worth noting
that we can have more than one Inspector window open at one time.
To open another Inspector window,
we can simply click the Menu button next to the lock
and choose Add Tab > Inspector.
This allows us to have one locked instance
of the Inspector window open,
and a second instance to show our current selection.
When we are finished with our locked instance,
we can either close the tab, if we are working
with multiple Inspector windows,
or click the lock icon again
to unlock the Inspector window.
The Inspector window has two modes available,
Normal Mode and Debug Mode.
In Normal Mode, the Inspector window
shows all of the publicly editable properties.
If a custom editor for that asset or Component is available,
the custom editor will be used.
In Debug Mode, the Inspector shows only the Component’s properties.
However, this mode shows all of the Component’s properties,
including private ones, making it far easier to debug
any unexpected or unwanted behavior.
It is also worth noting that although private variables
are displayed in Debug Mode, their values cannot be edited.
In many cases, individual Components
attached to a GameObject can be toggled on and off
by enabling or disabling the Component.
When a Component is disabled, the Component will be ignored
when the game is running.
It is possible to enable or disable many different combinations
of Components on a GameObject,
allowing us to experiment with how different Components work
or to explore different behaviors during development.
As we can see, the Inspector window is a simple and easy way to view
and to interact with and adjust the properties
of our GameObjects and assets.