Inheritance and Abstract Bases
Introduction
Section titled “Introduction”SIECS inheritance is built on the IsA relation.
A base entity contains reusable component data. An instance connects to the base:
ecs_is_a(instance, base);instance.is_a(base);The base is treated as abstract so normal simulation queries focus on concrete instances.
Inheritance is intended for reusable defaults and templates, not for recreating deep object-oriented class hierarchies.
Abstract bases
Section titled “Abstract bases”Create a base:
ecs_entity_t enemy = ecs_new();ecs_set(enemy, Health, {100});ecs_set(enemy, Speed, {2.5f});ecs_abstract(enemy);auto enemy = ecs::spawn() .set(Health{100}, Speed{2.5f}) .abstract();An entity used as an inheritance base is not meant to participate as a normal runtime instance.
Abstract entities are excluded from ordinary queries unless explicitly
requested.
Component Inheritance
Section titled “Component Inheritance”Every component chooses one inheritance policy at registration.
Owned inheritance
Section titled “Owned inheritance”EcsInheritOwned materializes the effective base value as owned data on the
instance.
Conceptually:
Base Health = 100instance IsA Baseinstance owns Health = copy of 100Later changes to the base do not automatically synchronize that copied value.
Owned inheritance is appropriate for values that are defaults at instantiation/inheritance time.
Shared inheritance
Section titled “Shared inheritance”EcsInheritShared keeps the value on the base.
Instances resolve it as a shared read-only field until they create an override.
Conceptually:
Base Material = SteelInstance A -> shared SteelInstance B -> shared SteelChanging the base changes what non-overridden instances read.
This is useful for data shared by many instances.
Component Overriding
Section titled “Component Overriding”An instance can set a component locally:
ecs_set(instance, Health, {500});instance.set(Health{500});If the component was inherited, the instance now has an owned override for the effective value.
Queries can distinguish owned vs shared fields with ecs_field_kind().
Writable query access requires writable owned storage. Shared inherited values must not be mutated through an instance field pointer.
Inheritance Checks
Section titled “Inheritance Checks”Test ancestry:
if (ecs_is(entity, base)) { /* entity is base or derives through IsA */}if (entity.is(base)) { // entity is base or derives through IsA}Get the direct base:
ecs_entity_t base = ecs_entity_base(entity);ecs::entity base = entity.target<ecs::IsA>();These operations let tools or gameplay code inspect inheritance without manually walking raw relation storage.
Query Matching
Section titled “Query Matching”Queries can match effective inherited data.
A read-only component term may resolve to shared data from a base.
ecs_query_id_t q = ecs_query({ .components = { ecs_in(Material) },});auto q = ecs::query().build();q.each([](const Material &material) {});For each batch, use ecs_field_kind() to determine whether the field is owned or
shared.
Writable Queries
Section titled “Writable Queries”Writable terms require local storage.
If a shared inherited component should be modified independently, create an override before running the writable operation.
This rule prevents a single instance from unintentionally modifying a value that other instances share from the same base.
Restrict a Query to a Base
Section titled “Restrict a Query to a Base”Use the query descriptor’s is_a field:
ecs_query_id_t enemies = ecs_query({ .components = { ecs_in(Health) }, .is_a = enemy_base,});auto enemies = ecs::query() .is_a(enemy_base) .build();enemies.each([](const Health &health) {});This matches descendants of the selected base.
The ancestry test is transitive.
Variants
Section titled “Variants”A useful template pattern is:
EnemyBase Health = 100 Speed = 2.5
FastEnemyBase IsA EnemyBase Speed = 5
Boss IsA EnemyBase Health = 1000Keep variant chains shallow enough that the effective data model stays obvious.
When a variant only differs by a small value, a normal component value can be simpler than creating another inheritance level.
Base hierarchies
Section titled “Base hierarchies”A base may own a ChildOf subtree.
ecs_abstract(base) propagates abstract state through that owned subtree, which
lets applications build template hierarchies that stay out of normal queries.
When instantiating a similar runtime hierarchy, application/module code can use the base structure as a model while creating concrete entities according to its needs.
SIECS does not expose prefab child slots or a
dedicated Prefab tag API. Use Abstract, IsA, component inheritance and
ChildOf explicitly.
Common Pattern
Section titled “Common Pattern”ECS_COMPONENT_DEFINE(Health, .inheritance = EcsInheritOwned);
ECS_COMPONENT_DEFINE(Material, .inheritance = EcsInheritShared);
ecs_entity_t enemy = ecs_new();ecs_set(enemy, Health, {100});ecs_set(enemy, Material, {.kind = Steel});ecs_abstract(enemy);
ecs_entity_t boss = ecs_new();ecs_is_a(boss, enemy);ecs_set(boss, Health, {500});ecs::component<Health>(ecs::component_options<Health>{ .inheritance = EcsInheritOwned,});ecs::component<Material>(ecs::component_options<Material>{ .inheritance = EcsInheritShared,});
auto enemy = ecs::spawn() .set(Health{100}, Material{ .kind = Steel }) .abstract();
auto boss = ecs::spawn() .is_a(enemy) .set(Health{500});boss owns its Health override while it can continue to share Material.
Design guidance
Section titled “Design guidance”Inheritance is most effective for:
- template defaults;
- shared immutable/configuration-like data;
- grouping instances by a conceptual base;
- tooling/template entities.
Prefer ordinary composition when behavior can be expressed by components without ancestry.
Prefer resources for world-global values.
Prefer relations for domain edges that are not “instance of this reusable base”.
Establishing IsA
Section titled “Establishing IsA”ecs_is_a(entity, base) changes structural inheritance state.
The runtime builds an inheritance plan for components that must become locally owned according to their registration policy.
For owned-inheritance components, effective base values are materialized on the instance.
For shared components, the base remains the storage source.
Because this can create/move component storage, establishing/changing a base is a structural operation.
Changing bases
Section titled “Changing bases”Retargeting IsA changes which effective data the instance sees.
Code that changes bases should consider:
- which owned components must be materialized;
- which shared values change source;
- whether existing local overrides remain;
- query cache/table transitions;
- observer implications.
Do not use base retargeting every frame as a substitute for a small state field unless the structural behavior is actually desired.
Shared field batching
Section titled “Shared field batching”A query can return a shared inherited field for a batch.
The batch groups entities for which the effective field source is compatible with the iterator representation.
Use ecs_field_kind() rather than assuming all batches in one query own their
data.
The same query can encounter owned and shared batches.
Overrides and queries
Section titled “Overrides and queries”Consider:
Base: Material = Steel (shared)
Instance A: IsA Base
Instance B: IsA Base Material = Gold (override)A read query for Material can match both.
For A, the field is shared from Base.
For B, the field is owned.
A writable query should operate on B’s local storage but must not mutate A’s shared base storage as though it belonged to A.
Inheritance versus ChildOf
Section titled “Inheritance versus ChildOf”IsA means reusable base/effective component inheritance.
ChildOf means hierarchy/ownership.
An entity can participate in both:
Soldier42 IsA SoldierBaseSoldier42 ChildOf Squad7Do not use IsA merely to express containment.
Do not use ChildOf to imply component inheritance.
Keeping these meanings separate makes queries and lifetime behavior clear.
Abstract base mutation
Section titled “Abstract base mutation”Because base values can be shared by many instances, changing a shared component on a base can affect many readers at once.
Treat base mutation like changing shared configuration.
If an instance needs independent state, override locally.
For high-frequency per-instance changes, use owned components rather than a shared base value.
Inheritance performance
Section titled “Inheritance performance”Inheritance can save memory for shared data but introduces source resolution.
The useful tradeoff is:
less duplicated dataversusadditional shared/inherited matching/access logicOwned inheritance copies data up front and then behaves like ordinary local storage.
Shared inheritance is most attractive when:
- many instances share the same value;
- reads are frequent;
- writes are rare and usually happen on the base;
- overrides are relatively uncommon.
Template design checklist
Section titled “Template design checklist”A base should represent a coherent reusable default.
Avoid chains where every small variation creates another base level.
Prefer:
- one stable base;
- a few meaningful variants;
- local component overrides for instance-specific differences.
Use ordinary tags/components to represent orthogonal capabilities instead of forcing them into a single inheritance tree.

