Entity

Description

The base object the engine simulates. It owns a Transform, a list of components (EntityComponent), and child entities. The constructors auto-register it into the Entities and EntitiesOnStart entity groups. Marking it dirty enqueues it into EntitiesToUpdate and cascades to children.

The ECS is currently class/object-based rather than data-oriented — a known piece of engine techdebt.

API summary

MemberKindSummary
CreateComponent<T>()publicAdd a component (special-cases MeshComponent → the renderer’s mesh type).
GetComponent<T>() / RemoveComponent<T>()publicFind / remove a component by type.
AddChild(Entity) / CreateChildEntity<T>()virtualParent another entity.
GetChildEntityByName / GetAllChildrenEntitiesByName / GetAllChildrenEntitiesvirtualChild queries.
MarkDirty()publicSet isDirty (enqueues for GPU update).
Invalidate()virtualFire OnInvalidate on components + enqueue for update.
OnStart / OnEnable / OnDisable / OnTick / OnDestroyvirtualLifecycle — forward to components.

Fields & Properties

[@Serializable] bool enabled = true;
[@Serializable] public Transform transform;
[@Serializable] public string name = "entity";
[@Serializable] public List<EntityComponent> _components = new();
[@Serializable] public List<Entity> children = new();
[NonSerializable] public Entity parent;

[NonSerializable] public bool isDirty   // setter → EntityRegistry.AddToGroup("EntitiesToUpdate", this) + cascades to children

Methods

Lifecycle

OnStart/OnEnable/OnDisable/OnTick/OnDestroy simply iterate _components and call the matching hook on each (see EntityComponent).

Components

CreateComponent<T>() instantiates and attaches a component (no duplicates). For MeshComponent it picks the concrete mesh type from Renderer.renderingModules[0].rendererType (MCRaster / MCUI / MCRaytracing). GetComponent<T> / RemoveComponent<T> scan _components by type.

Dirty / update

The isDirty setter (and MarkDirty()) register the entity into the EntitiesToUpdate group via EntityRegistry and propagate dirtiness to all children. Invalidate() additionally calls OnInvalidate on each component.