Introduction – Important information about GameObjects
GameObjects form the fundamental building blocks of every Unity scene, with each one containing at least a Transform component by default. This essential component tracks the object’s position, rotation, and scale within the 3D world. To create functional elements in your game, you extend these basic GameObjects by adding specialized components that define their behavior and properties. For instance, a camera in Unity is essentially a GameObject enhanced with both Camera and AudioListener components, transforming a simple object into the player’s viewport and audio receiver.

When a GameObject is active in the hierarchy and the game is running, Unity periodically updates each of its components and executes some other functions, all this automatically. If we deactivate the GameObject, this process will not take place and we will achieve the effect that the GameObject disappears from the scene.
During runtime, Unity automatically processes all active GameObjects in your hierarchy, executing their component update functions each frame according to their scripting implementation. When you disable a GameObject by setting it to inactive, Unity suspends this update process for both the object and all its children, effectively removing it from the scene rendering pipeline. This not only makes the GameObject visually disappear but also prevents its components from consuming processing resources—an important optimization technique for managing scene performance and object lifecycles.
For a visual breakdown of this subject, you may find my video discussion helpful:
How to manually activate and deactivate objects in Unity
As previously noted, every GameObject in Unity must contain at least one Transform component—this is mandatory and cannot be removed. When you select a GameObject in the Hierarchy window, the Inspector panel will display its Transform properties along with the header section (visible in Figures 2 and 3).


The checkbox highlighted in both images is the GameObject’s active state toggle. When enabled (checked), the GameObject remains active in the scene. When disabled (unchecked), the GameObject becomes inactive—effectively behaving as if it were removed from the scene. In the Hierarchy window, inactive GameObjects appear visually muted, as shown in Figure 4.

Activate and Deactivate GameObject using Script
Of course we could get more out of this if we could activate and deactivate one or more GameObjects through a Script, this would allow us for example to make enemies appear when the player reaches a certain part of the map, make a final screen appear when the player loses the game and more.
Let’s start by creating a new Script and GameObject in the hierarchy to which to assign the Script.


In figure 7 you can see that the new GameObject is assigned the script we created. This can be done by dragging the script directly or by using the Add Component button and searching for the script by name.

To be able to activate or deactivate the GameObject from a Script we need to have the reference of the GameObject we want to activate or deactivate, so inside our Script we are going to define a public GameObject, in this case I have called it “gameObjectToDeactivate”, trying that the name reflects as much as possible the function it is going to perform.

When defining the public reference, this object will appear in the GameObject inspector that the script has assigned, as we see in figure 9, this will allow us to manually assign the object we want to activate and deactivate, in our case the first object we had was called “GameObject”, in figure 10 you can see how the field has been filled with this object.


Instruction to activate or deactivate a GameObject in Unity
The function that allows us to change the Activation status of a GameObject is “SetActive”, it is a method that receives as a parameter a boolean value (true or false) and this function is called on a GameObject, in this case we use the reference that we have defined, as seen in lines 22 and 27, we are deactivating and activating the GameObject respectively.
In this particular example we are reading the A and D keys to execute the functions, this means that if the player presses the A key, the instruction “SetActive(false)” is executed which disables the GameObject and if the player presses the D key, the instruction “SetActive(true)” is executed which enables the GameObject.

Executing those instructions is exactly equivalent to checking or unchecking that box in the inspector we saw in figures 2 and 3.
You have reach the end of the article, if it was useful consider subscribing to the channel!