Use this when an object should stay in the scene but temporarily stop participating in the game.
Active in the Inspector
The GameObject header in the Inspector has an active checkbox.
When the checkbox is on, the GameObject is active. When the checkbox is off, the GameObject is inactive.
Inactive objects are useful for:
- disabled menus
- hidden effects
- alternate player weapons
- paused or locked interactables
- objects that should be enabled later by gameplay
Parents Affect Children
Active state follows the hierarchy.
If a parent GameObject is inactive, its children are inactive in the scene even if their own checkboxes are on.
That gives you two useful questions:
isActiveSelf()asks whether this object itself is checked onisActiveInHierarchy()asks whether this object is actually active after parents are considered
Use isActiveInHierarchy() when gameplay needs to know whether an object is really live in the scene.
Toggle from a Behaviour
Gameplay code can activate or deactivate GameObjects with setActive().
<?php
declare(strict_types=1);
namespace MyGame\Game\Scripts;
use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\GameObject;
final class ShieldToggle extends Behaviour
{
public ?GameObject $shield = null;
public function setShieldVisible(bool $visible): void
{
$this->shield?->setActive($visible);
}
}
Expose object references like this when a designer should choose the target in the Inspector.
Use Active State for Presence, Not Data
Deactivate a GameObject when you want it out of play.
Do not use active state as a replacement for real gameplay state. For example, a locked door may still need data such as who owns the key, whether it can be unlocked, and what sound it should play. The active checkbox only answers whether the object is present and participating.