Skip to content

Components

All components extend AbstractComponent and use #[Serializable] for automatic serialization. Attributes live in PHPolygon\ECS\Attribute.

3D Components

ComponentKey PropertiesPurpose
Transform3Dposition: Vec3, rotation: Quaternion, scale: Vec3, parentEntityId: ?intWorld/local transform with hierarchy
Camera3DComponentfov: float, near: float, far: float, projectionType: ProjectionType, active: boolProjection settings
MeshRenderermeshId: string, materialId: string, castShadows: boolRenderable mesh
DirectionalLightdirection: Vec3, color: Color, intensity: floatSun/moon light
PointLightcolor: Color, intensity: float, radius: floatPositional light

2D Components

ComponentKey PropertiesPurpose
Transform2Dposition: Vec2, rotation: float, scale: Vec2, parentEntityId: ?int2D transform with hierarchy
Camera2DComponentzoom: float, bounds: ?Rect, active: bool2D orthographic camera
SpriteRenderertextureId: string, region: ?Rect, color: Color, layer: int, flipX/Y: bool, opacity: float2D sprite rendering

Physics 3D Components

ComponentKey PropertiesPurpose
CharacterController3Dheight, radius, stepHeight, slopeLimitCapsule collision controller
RigidBody3DbodyType: BodyType, mass, gravityScale, linearDamping, restitution, frictionPhysics body (Static/Kinematic/Dynamic)
BoxCollider3Dsize: Vec3, offset: Vec3, isTrigger: bool, isStatic: boolAABB box collider
MeshCollider3DmeshId: string, isStatic: bool, isTrigger: boolTriangle mesh collider with BVH
HeightmapCollider3DgridWidth, gridDepth, worldMinX/MaxX/MinZ/MaxZO(1) terrain collision
HingeJointanchorOffset: Vec3, axis: Vec3, angle, minAngle, maxAngle, dampingRevolute joint for doors/gates
LinearJointslideAxis: Vec3, position, minPosition, maxPosition, dampingPrismatic joint for sliding doors

Physics 2D Components

ComponentKey PropertiesPurpose
RigidBody2Dvelocity: Vec2, mass, drag, angularVelocity, gravityScale, restitution, isKinematic2D physics body
BoxCollider2Doffset: Vec2, size: Vec2, isTrigger: bool2D box collider

Environmental Components

ComponentKey PropertiesPurpose
AtmospherecloudBaseAltitude, airPressureAtmospheric simulation (pressure, visibility, thermals)
WindbaseIntensity, gustiness, gustFrequencyWind simulation with layered gusts
DayNightCycletimeOfDay: float, dayDuration, speed, paused: bool, lunarCycleDaysDay/night cycle (0.0-1.0 time)
WeathercloudCoverage, humidity, transitionDurationWeather state machine (Clear/Cloudy/Rain/Snow/Storm/Fog)
SeasonyearProgress, yearDuration, speedSeasonal cycle (spring/summer/fall/winter)

Animation Components

ComponentKey PropertiesPurpose
PalmSwayswayStrength, phaseOffset, isTrunk: boolWind-driven sway for vegetation

Terrain Components

ComponentKey PropertiesPurpose
InstancedTerrainmeshId: string, matricesByMaterial: array<string, list<Mat4>>Pre-computed instanced terrain

Audio Components

ComponentKey PropertiesPurpose
AudioSourceclipId: string, volume: float, loop: bool, playOnAwake: boolAudio playback

Utility Components

ComponentKey PropertiesPurpose
NameTagname: stringEntity name for debugging/referencing

Custom Components

php
use PHPolygon\ECS\AbstractComponent;
use PHPolygon\ECS\Attribute\Serializable;
use PHPolygon\ECS\Attribute\Property;
use PHPolygon\ECS\Attribute\Category;
use PHPolygon\ECS\Attribute\Range;
use PHPolygon\ECS\Attribute\Hidden;

#[Serializable]
#[Category('Gameplay')]
class Inventory extends AbstractComponent
{
    #[Property]
    public int $maxSlots = 20;

    #[Property(editorHint: 'slider')]
    #[Range(min: 0, max: 100)]
    public int $weight = 0;

    #[Hidden]
    public array $items = [];

    public function addItem(string $itemId): bool
    {
        if (count($this->items) >= $this->maxSlots) {
            return false;
        }
        $this->items[] = $itemId;
        return true;
    }
}

Component Attributes

AttributeTargetParametersPurpose
#[Serializable]Class?string $nameMarks component for serialization & editor discovery
#[Property]Property?string $name, ?string $type, ?string $editorHint, ?string $descriptionExposes property to editor
#[Hidden]Property-Hides property from editor
#[Category]Classstring $nameGroups properties in inspector (Core, Rendering, Physics, etc.)
#[Range]Propertyfloat $min, float $maxNumeric range constraints for sliders

Naming Convention

Component classes use noun names without suffix: MeshRenderer, BoxCollider2D, Transform3D.

Released under the MIT License.