Skip to main content
Methods for saving/restoring simulation snapshots and manipulating joint state.

saveState()

Capture a snapshot of the current simulation state.
Returns: StateSnapshot

restoreState(snapshot)

Restore a previously saved state.
StateSnapshot
required
Snapshot from a previous saveState() call.

setQpos(values)

Set all generalized positions.
Float64Array | number[]
required
Array of length model.nq.

getQpos()

Get all generalized positions.
Returns: Float64Array

setQvel(values)

Set all generalized velocities.
Float64Array | number[]
required
Array of length model.nv.

getQvel()

Get all generalized velocities.
Returns: Float64Array

applyKeyframe(nameOrIndex)

Apply a named or indexed keyframe from the model.
string | number
required
Keyframe name or index. Keyframes are defined in MJCF with <key> elements.

getKeyframeNames()

Get all keyframe names.
Returns: string[]

getKeyframeCount()

Get the number of keyframes.
Returns: number

Example: Checkpoint System

New snapshots include the full mjSTATE_INTEGRATION vector: mocap poses, external forces, solver warmstart, history, equality activation, and plugin state. Restore requires the same loaded model; snapshots are in-memory objects, not portable serialized assets. Legacy fields remain editable and are applied after the packed state. Legacy snapshots without integration restore only their explicit fields. MuJoCo’s experimental IPC flex contact retains additional private state, so exact replay of IPC contact is unsupported.