For the complete documentation index, see llms.txt. This page is also available as Markdown.

The Server Update Loop

Summary

How to run code each frame on the server, and where your code sits relative to physics. For the full per-frame execution order, see Server Execution Order. This page is part of the Reactor Technical Overview.

Running Code Each Frame

Server scripts do not override an Update method. Instead you register a handler on the room's ordered update event, keyed by an integer that sets when it runs:

public override void Initialize()
{
    Room.OnUpdate[10] += MyUpdate;   // runs after physics
}

public override void Detached()
{
    Room.OnUpdate[10] -= MyUpdate;   // always unregister
}

private void MyUpdate() { /* per-frame logic */ }

Register in Initialize and unregister in Detached. Room, player, and entity scripts all use this same room-level event; there is no separate per-entity update method.

Order and Physics

Handlers run in order of their integer key. The physics step, when the room uses it, runs at the boundary between negative and non-negative keys: handlers with a negative key run before physics, and handlers with a zero or positive key run after. Choose a negative key to act before physics, for example to apply forces, and a non-negative key to read the settled result.

Setting Room.SkipFrameUpdates to true during a handler stops handlers with a higher key from running this frame. It does not stop other handlers registered with the same key.

For the full order of a frame, including where input, RPCs, and syncs fall, see Server Execution Order.

Time

Read time from Room.Time: the current Frame, total simulated Time, RealDelta (real seconds since the last frame), FramesUntilSync (frames until the next sync), and TimeScale, a multiplier you set to speed up or slow down simulated time. See Changing Simulation Time.

Where to Go Next

Last updated