Guides GameObjects GameObject Fundamentals

GameObjects 2 min read Updated Apr 2026

GameObject Fundamentals

A GameObject is the scene object Lenga stores, selects, edits, and exposes to your code.

When you click something in the Hierarchy or the Scene view, you are usually selecting a GameObject. The Inspector then shows the data that belongs to that object.

The Parts Every GameObject Has

Every GameObject has a few pieces that make it understandable to the editor and to the runtime:

  • a name, so you can find it in the Hierarchy
  • an active state, so it can be enabled or disabled
  • a tag, so gameplay code can recognize its role
  • a layer, so systems such as physics can group it
  • a Transform, so it has position, rotation, and scale
  • a list of components, so it can render, collide, play sounds, or run code
  • an optional parent and children, so it can live inside a hierarchy

The important idea is that the GameObject is not the behaviour by itself. It is the object that owns the behaviour-producing pieces.

The GameObject Class

When scene-attached gameplay code needs the object it belongs to, the same object appears as Lenga\Engine\Core\GameObject.

Inside a Behaviour, $this->gameObject refers to the GameObject that owns that Behaviour component.

<?php

declare(strict_types=1);

namespace MyGame\Game\Scripts;

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Debug;

final class ObjectReporter extends Behaviour
{
    public function start(): void
    {
        Debug::log('I belong to: ' . $this->gameObject->name);
    }
}

That Behaviour does not create a new object. It reports the object it is attached to.

What Belongs on the GameObject?

Use the GameObject for identity and organization:

  • name it clearly
  • tag it when gameplay needs to recognize it
  • place it on the right layer
  • keep related children under it
  • attach the components that give it capabilities

Use components for specialized behavior:

  • renderers draw things
  • colliders define collision shapes
  • rigidbodies make physics move objects
  • audio components play sounds
  • Behaviours hold game-specific logic that belongs on the object

Use ordinary PHP classes for calculations, helpers, and reusable domain code that does not need to be selected, enabled, disabled, or tuned in the Inspector.

That split keeps the scene readable. A Player GameObject can stay the player while its components explain how it looks, moves, collides, and responds to input.

What Comes Next