Guides GameObjects Assign Tags and Layers to GameObjects

GameObjects 2 min read Updated Apr 2026

Assign Tags and Layers to GameObjects

Tags and layers help Lenga answer different questions about a GameObject.

A tag describes what an object is for gameplay. A layer describes what group it belongs to for engine systems such as 2D physics.

Tags Identify Roles

Use tags when gameplay needs to recognize an object by role.

Examples:

  • Player
  • Enemy
  • Pickup
  • Hazard
  • Checkpoint

The Inspector shows the selected GameObject's tag near the top of the object header. Use the edit button beside the tag field when you need to manage the project's tag list.

Layers Group Objects for Systems

Layers are numeric groups.

Use layers when a system needs to treat groups of GameObjects differently. For example, 2D physics can use layers to decide which objects should collide with each other.

Lenga projects have 32 physics layers available, numbered 0 through 31.

Use layer names and collision settings in project settings to keep layer meaning consistent across the project.

Tags in Gameplay Code

Use compareTag() when checking one object.

Use GameObject::findGameObjectsWithTag() when you need to find objects that share a role.

<?php

declare(strict_types=1);

namespace MyGame\Game\Scripts;

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

final class EnemyCounter extends Behaviour
{
    public function start(): void
    {
        foreach (GameObject::findGameObjectsWithTag('Enemy') as $enemy) {
            Debug::log('Enemy in scene: ' . $enemy->name);
        }
    }
}

Prefer tags for meaning. Prefer layers for filtering and grouping.

Naming Discipline Matters

Tags and layers become project vocabulary.

Use a small, clear set instead of inventing near-duplicates such as Enemy, Enemies, BadGuy, and Monster for the same role.

That discipline helps scenes, scripts, physics settings, and team conversations stay aligned.

What Comes Next