Resources
Resources are typed values stored once per world.
They are the SIECS mechanism for state that is global to the current world:
- frame timing;
- input state;
- renderer/device handles;
- configuration;
- asset registries;
- networking state;
- application services represented as data.
Resources use a separate ecs_resource_t id space. They do not become entity
components and do not affect archetypes.
Declare a resource
Section titled “Declare a resource”ECS_RESOURCE(Time, { float dt; float elapsed;});
ECS_RESOURCE_REGISTER(Time);
const ecs_resource_info_t *info = ecs_resource_info(ecs_id(Time));/* info->type is the reflected type handle. */struct Time { float dt; float elapsed;};
auto time = ecs::resource<Time>();Shared C declarations can be used from both C and C++. C++ native types can use the typed resource wrapper directly.
The fields in ECS_RESOURCE_DECLARE also define the reflection descriptor.
Register dependent structs and enums with Sireflect before registering the
resource. Resources containing opaque external types can explicitly use
ECS_RESOURCE_DEFINE_UNREFLECTED in their definition file.
Reflected resources appear in GET /schema under resources, with their
complete type graph in types. The REST module exposes present resources at
GET /resources and GET /resources/:id. PUT /resources/:id replaces the
complete value; PATCH /resources/:id accepts a recursive subset under
{"value": {...}}. Arrays are replaced as complete arrays. A field marked
readonly=true in Sireflect metadata cannot be changed through these routes.
Set and read
Section titled “Set and read”ecs_set_resource(Time, { .dt = 0.016f, .elapsed = 0.0f,});
Time *time = ecs_get_resource(Time);const Time *read_time = ecs_get_resource_read(Time);auto time = ecs::resource<Time>();time.set(Time{ .dt = 0.016f, .elapsed = 0.0f });
Time &writable_time = time.edit();const Time &read_time = time.get();Nullable access:
Time *time = ecs_try_get_resource(Time);const Time *read_time = ecs_try_get_resource_read(Time);auto time = ecs::resource<Time>();Time *writable_time = time.try_edit();const Time *read_time = time.try_get();The non-try getters require the resource to exist. In C++, get() and
try_get() expose read-only storage; edit() and try_edit() explicitly
request writable storage. A resource<const T>() handle cannot set, edit, or
remove the resource. Creating a handle and checking presence do not register
an absent resource type.
Presence and removal
Section titled “Presence and removal”if (ecs_has_resource(Time)) { ecs_remove_resource(Time);}auto time = ecs::resource<Time>();if (time.has()) { time.remove();}Removing a missing resource is a no-op.
Resource hooks
Section titled “Resource hooks”A resource descriptor can define on_set and on_remove.
Hooks are appropriate for small lifecycle reactions tied to the resource value.
on_remove also runs during world teardown for resources that remain present.
Resources in systems
Section titled “Resources in systems”Resource terms do not match entities and do not consume ecs_field() slots.
They declare scheduler access:
ecs_system({ .name = "Move", .phase = EcsOnUpdate, .query = { .components = { ecs_inout(Position), ecs_in(Velocity), }, .resources = { { .id = ecs_id(Time), .access = EcsIn }, }, }, .callback = Move,});ecs::system("Move") .phase(EcsOnUpdate) .each([](Position &position, const Velocity &velocity, ecs::res<const Time> time) { position.x += velocity.x * time->dt; position.y += velocity.y * time->dt; });The scheduler can use this access to prevent a resource writer from running in parallel with conflicting readers/writers.
In C++, typed system callbacks can request ecs::res<T> / ecs::res<const T>.
Builtin DeltaTime
Section titled “Builtin DeltaTime”SIECS registers DeltaTime.
It contains the current frame delta. This is useful for systems that want the world’s frame time as data.
For an interval system, it->delta_time can represent accumulated time since
the system’s previous automatic execution, while the DeltaTime resource still
represents the current frame.
ID-based API
Section titled “ID-based API”Generic code can use:
ecs_resource_init;ecs_resource_find;ecs_resource_name;ecs_set_resource_id/ecs_move_resource_id;ecs_get_resource_id;ecs_try_get_resource_id;ecs_has_resource_id;ecs_remove_resource_id.
Raw-id variants follow one naming rule: components use the _cid suffix
(ecs_set_cid), relations and resources use _id (ecs_relate_id,
ecs_set_resource_id). ecs_rid(T) always names a relation id.
Resource lookup is direct by resource id and does not involve archetype matching.
Resource design
Section titled “Resource design”Use a resource when there should be exactly one value for the world.
Use a component when the value belongs independently to entities.
Avoid turning a resource into a large mutable service object that hides all dependencies. Systems are easier to schedule and test when resource access is explicit and narrowly scoped.
Resource registration and type operations
Section titled “Resource registration and type operations”ecs_resource_desc_t contains:
- name;
- size;
- type lifecycle operations;
on_set;on_remove.
C++ resource wrappers register appropriate lifecycle operations for native types.
Like components, a resource that owns memory/handles must have correct lifetime semantics.
Unlike components, there is only one storage slot per registered resource type in the world.
Resource initialization patterns
Section titled “Resource initialization patterns”Configuration
Section titled “Configuration”Set once during startup/module import and read from many systems.
GameConfigRendererConfigPhysicsSettingsFrame state
Section titled “Frame state”Update once per frame and read from many systems.
InputDeltaTimeFrameInfoMutable service state
Section titled “Mutable service state”A resource can hold mutable runtime state such as an asset registry.
If many systems write it, the scheduler will serialize those systems according to declared access.
Consider splitting unrelated service state into separate resources to expose more parallelism and clearer dependencies.
Resource lifetime
Section titled “Resource lifetime”A registered resource type can be present or absent.
set creates/replaces the current value.
remove destroys/removes the current value but the resource type remains
registered.
During ecs_fini(), present resources are finalized according to runtime
registration/lifecycle ordering.
Do not retain a resource pointer after removal or world finalization.
Resources and modules
Section titled “Resources and modules”A module may register/set resources needed by its systems.
Disabling the module disables captured systems/observers but does not automatically remove every resource value.
This is intentional: resource lifetime is separate from module execution state.
If a module owns a resource that should disappear on disable, implement that policy explicitly.
Scheduler examples
Section titled “Scheduler examples”Two read-only resource consumers can run together:
System A: Time [in]System B: Time [in]A writer conflicts:
System C: Time [inout]If a resource is accessed through an undeclared global pointer instead, the scheduler cannot infer that conflict.
This is why explicit resource terms are useful even though the callback can technically call the resource getter directly.

