ListOf

Applies to: properties typed as array

Namespace:

namespace Lenga\Engine\Attributes;

Describes the element type of an Inspector-visible array. Use it when an array should be edited as an expandable list instead of an untyped JSON value.

Parameters

Parameter Type Description
$listType class-string The type used for each list element.

Example

use Lenga\Engine\Attributes\ListOf;
use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\GameObject;
use Lenga\Engine\Core\Vector3;

final class Waypoint
{
    public string $label = '';
    public Vector3 $position;
}

final class PatrolRoute extends Behaviour
{
    /** @var array<int, GameObject> */
    #[ListOf(GameObject::class)]
    public array $targets = [];

    /** @var array<int, Waypoint> */
    #[ListOf(Waypoint::class)]
    public array $waypoints = [];
}

targets renders as a list of scene-object pickers. waypoints renders as a list of nested object editors, with each Waypoint exposing its own serialized fields.

Runtime Shape

Lenga hydrates supported list elements before Behaviour lifecycle methods run:

  • engine value types such as Vector2, Vector3, Vector4, and Color
  • scene references such as GameObject, components, UI elements, AudioClip, and AudioMixer
  • custom PHP classes with serialized/public fields

Keep the PHP property typed as array, and add a docblock such as /** @var array<int, Waypoint> */ so tools understand the expected element type.