RewindableStateMachine

Inherits: Node

A state machine that can be used with rollback.

Description

It relies on RollbackSynchronizer to manage its state. State transitions are only triggered by gameplay code, and not by rollback reverting to an earlier state.

For this node to work correctly, a RollbackSynchronizer must be added as a sibling, and it must have the RewindableStateMachine's state property configured as a state property.

To implement states, extend the RewindableState class and add it as a child node.

Tutorials

Properties

Type Name Default
StringName state &""

Methods

Return Type Name
bool transition(StringName new_state_name)
void update_states()

Signals

on_state_changed ( RewindableState old_state, RewindableState new_state )

Emitted during state transitions. This signal can be used to run gameplay code on state changes.

This signal is emitted whenever a transition happens during rollback, which means it may be emitted multiple times for the same transition if it gets resimulated during rollback.

State changes are not necessarily emitted on all peers.
See: RewindableStateMachine caveats


on_display_state_changed ( RewindableState old_state, RewindableState new_state )

Emitted after the displayed state has changed. This signal can be used to update visuals based on state changes.

This signal is emitted whenever the state after a tick loop has changed.


Property Descriptions

StringName state = &""

Name of the current state. Can be an empty string if no state is active. Only modify directly if you need to skip transition()'s callbacks.


Method Descriptions

bool transition ( StringName new_state_name )

Transition to a new state specified by new_state_name and return true. Finds the given state by name and transitions to it if possible. The new state's RewindableState.can_enter() callback decides if it can be entered from the current state.

Upon transitioning, RewindableState.exit() is called on the old state, and RewindableState.enter() is called on the new state. In addition, on_state_changed() is emitted.

Does nothing if transitioning to the currently active state. Emits a warning and does nothing when transitioning to an unknown state.


void update_states ( )

Update the internal cache of known states

Automatically called on ready and when a child node is added or removed. Call manually to force an update.