Entity Type
Tags an entity with the kind it was created from (cube, sphere, model, directionalLight, etc.). Factories use this to drive kind-specific behavior; the editor inspector uses it to select component editors.
Properties
| Property | Type | Description |
|---|---|---|
value | EcsEntityKind | EcsEntityEditorKind | Kind tag identifying which factory created this entity (e.g. cube, directionalLight, model). |
API reference
- Class:
EntityType - Source:
core/components/EntityType.ts
Scripting examples
Component access patterns
Use this.getComponent(X) to access a component on the entity this script is attached to. Use this.world.getEntityByName to find another entity by name, then this.world.getComponent to read its component:
// Component on the entity this script is on
const type = this.getComponent(EntityType);
// Component on another entity, found by its scene name
const other = this.world.getEntityByName("Enemy");
if (other) {
const type = this.world.getComponent(other.entityId, EntityType);
}Read the entity's own type tag
Branch behaviour based on what kind of entity this script is attached to.
import { Behaviour, EntityType } from "@relu-interactives/spatial-ecs";
export default class TypeAwareSetup extends Behaviour {
protected init() {
const entityType = this.getComponent(EntityType);
if (!entityType) return;
if (entityType.value === "cube") {
// Run cube-specific logic
this.transform.scale.x = 2;
} else if (entityType.value === "sphere") {
// Run sphere-specific logic
this.transform.scale.x = 1.5;
}
}
}Filter a world query by entity kind
Iterate all entities in the scene and apply logic only to those of a specific type.
import { Behaviour, EntityType, TransformComponent } from "@relu-interactives/spatial-ecs";
import type { StringInput, FloatInput } from "@relu-interactives/spatial-ecs";
export default class TypeFilter extends Behaviour {
data = {
targetKind: "cube" as StringInput,
spinSpeed: 1 as FloatInput,
};
protected onUpdate() {
for (const [id, entityType] of this.world.query([EntityType])) {
if (entityType.value !== this.data.targetKind) continue;
const t = this.world.getComponent(id, TransformComponent);
if (t) t.rotation.y += this.data.spinSpeed * this.deltaTime;
}
}
}Read-only tag
EntityType.value is set by the factory that created the entity and should be treated as read-only. Do not mutate it at runtime — it is used by the editor inspector and by hydration to select the correct component editors and restore the correct factory state.
Via ComponentInput in the inspector
You can also pick this component from the inspector using a ComponentInput field. Assign any entity in the inspector and the field resolves to the live EntityType instance at runtime.
import {
Behaviour,
EntityType,
type ComponentInput,
} from "@relu-interactives/spatial-ecs";
export default class Example extends Behaviour {
data = {
targetEntityType: {
type: "component",
value: null,
} as unknown as ComponentInput,
};
protected onUpdate() {
const entityType = this.data.targetEntityType.value as EntityType | null;
if (!entityType) return;
// Use the live component instance.
}
}Via EntityInput in the inspector
Alternatively, pick an entity from the inspector using an EntityInput field and then read the component off that entity via world.getComponent:
import {
Behaviour,
EntityType,
type EntityInput,
type WorldEntityView,
} from "@relu-interactives/spatial-ecs";
export default class Example extends Behaviour {
data = {
targetEntity: { type: "entity", value: null } as unknown as EntityInput,
};
protected onUpdate() {
const entity = this.data.targetEntity.value as WorldEntityView | null;
if (!entity) return;
const entityType = this.world.getComponent(
entity.entityId,
EntityType,
) as EntityType | null;
if (!entityType) return;
// Use the component on the picked entity.
}
}
