Skip to content

Modules

Modules group components, relations, systems and observers behind one import entry point.

A module is a registration/lifecycle unit. Entities are not “inside” modules and disabling a module does not erase component data.

ECS_MODULE_DECLARE(physics, {
float gravity;
});

Define in one implementation unit:

ECS_MODULE_DEFINE(physics);
void physics_import(const physics_props_t *props) {
(void)props;
ECS_COMPONENT_REGISTER(Position);
ECS_COMPONENT_REGISTER(Velocity);
ecs_system({
.name = "Move",
.phase = EcsOnUpdate,
.callback = Move,
});
}

Import:

ecs_module_id_t Physics = ECS_MODULE_IMPORT(physics, {
.gravity = 9.81f,
});

The generated module declarations can be consumed from C++ and SIECS also provides typed import/module wrappers.

The important semantic rule is the same: importing establishes registrations in the active world.

Importing the same module again returns the existing module registration rather than duplicating systems and observers.

The first import configuration is the one used for the module initialization.

This makes it safe for modules to depend on/import other modules without every caller coordinating a single central registration location.

While a module import is active, SIECS records systems and observers registered through the public API as belonging to that module.

Components and relations remain globally registered types.

Nested module import is supported: after a nested import completes, registrations resume being captured by the parent import.

ecs_module_disable(Physics);
ecs_module_enable(Physics);

Disabling a module disables captured systems and observers.

It does not:

  • unregister components;
  • remove components from entities;
  • destroy entities;
  • remove relation definitions.

This makes module toggling suitable for optional features and editor/runtime feature activation.

SIECS exposes ecs_module_load(path) for platform-supported dynamic module loading.

Dynamic loading is a deployment feature and should keep the same registration contracts as statically linked module imports.

A dynamically loaded module must be compatible with the runtime ABI and the application’s component/relationship expectations.

A module may import another module before registering its own systems.

System execution order is still defined by phases, data dependencies and explicit system .after relationships—not by module import order alone.

Do not use module import order as a substitute for scheduler dependencies.

Because modules can be enabled/disabled while component types and entity data remain intact, applications can implement optional execution features without rebuilding the whole ECS schema.

For mutually exclusive implementations, keep shared data contracts in stable components/resources and toggle the systems/observers that implement behavior.

Module capture happens during registration.

Normal query iteration does not pay a per-entity “which module owns this?” check.

Enable/disable cost is proportional to the captured registrations that must be toggled.

Module property structs are import-time configuration.

They are not automatically stored as a persistent ECS resource.

If systems need the configuration every frame, copy/store it into:

  • a resource;
  • component data;
  • module-owned user data;

according to the desired visibility and scheduling semantics.

The first successful idempotent import owns the initialization configuration.

A module can have no meaningful properties and still provide a registration boundary.

This is useful for feature packs such as:

Input
Rendering
DebugTools
GameplayRules

The module still captures its systems/observers for enable/disable.

A loaded module library must remain valid while callbacks/types originating from it are registered and used.

Do not unload code that still owns system/observer callback function pointers.

Treat dynamic module loading as application-level plugin lifecycle, not only an ECS registration call.

A high-level module can import lower-level modules:

Game
├── Physics
├── Rendering
└── AI

Idempotent import prevents duplicates if another module also depends on Physics.

Keep dependency direction acyclic at the module design level to avoid confusing initialization relationships even if import calls themselves are guarded.

Modules make tests easier when a subsystem can be imported into a fresh world.

A test can:

  1. initialize world;
  2. import module;
  3. create minimal entities/resources;
  4. run one phase/system;
  5. inspect result;
  6. finalize.

Avoid modules that require unrelated global application initialization when a smaller explicit resource/dependency would suffice.