Skip to content

Scheduler

Defined in: scheduler/scheduler.ts:103

The type for the scheduler created with scheduler.

configureSet(schedule, set, config): this

Defined in: scheduler/scheduler.ts:213

Configures a SystemSet for the specified schedule with the given config.

Schedules

SystemSet

SetConfig

this

System set configuration is per schedule, meaning the same system set can be configured differently for each schedule.

const sense = new SystemSet('sense')
const think = new SystemSet('think')
const act = new SystemSet('act')
scheduler()
// System sets that don't need configuration don't need to be configured.
.configureSet('update', think, { after: sense })
.configureSet('update', act, { after: think })
.run()

run(): void

Defined in: scheduler/scheduler.ts:282

Builds all plugins and then initializes every schedule.

void

Throws if run is called while the scheduler is already running.

When a schedule is initialized, an entity representing it is spawned and all related systems are made children of it.


usePlugin<Args>(pluginFn, …args): this

Defined in: scheduler/scheduler.ts:245

Registers a plugin function to be run before the scheduler starts. This function is given the scheduler and anything else passed in ...args.

Args extends unknown[]

PluginFn<Args>

Args

this

Throws when given an arrow function, as plugins strictly require an inferable name.

function physics(scheduler: Scheduler, gravity: number) {
scheduler.useSystem('update', updatePhysics, { args: gravity })
}
scheduler()
.usePlugin(physics, 196.2)
.run()

After a plugin is built, it becomes an entity with the Plugin component. This allows you to inspect metadata about the plugin and manipulate it.

Additionally, every entity spawned within a plugin is automatically given the pair(AddedByPlugin, pluginEntity) relationship.


useSystem<Args>(schedule, systemFn, config?): this

Defined in: scheduler/scheduler.ts:160

Schedules a system to run in the specified schedule with the provided arguments.

Optionally, a SystemConfig can be passed to configure the system, such as specifying when it should run or in which system set it should belong.

Args extends unknown[]

Schedules

SystemFn<Args>

SystemConfig<Args>

this

It cannot be assumed that two systems scheduled in the same phase will run in the order they were registered. Instead, consider using useSystemChain.

scheduler()
.useSystem('update', runsFirst)
.useSystem('update', runsSecond, { after: runsFirst })
.run()

After a system is scheduled, it becomes an entity with the System component. This allows you to inspect metadata about the system and manipulate it.

Additionally, the system is automatically made a child of its schedule (i.e. pair(ChildOf, scheduleEntity)).


useSystemChain(schedule, …systemFns): this

Defined in: scheduler/scheduler.ts:184

Schedules a chain of systems to run in order in the specified schedule, with an optional SystemConfig for each system.

Schedules

…(SystemFn | [SystemFn, SystemConfig<unknown[]>])[]

this

scheduler()
.useSystemChain('update', [
gatherInput, // Implicitly runs before `drawUI`.
[drawUI, { runIf: !inCinematicMode }],
])
.run()