Enum-based state machine with typed transitions, variant data storage, auto-forward, semaphore-locked actions, and debug output.
// Define an enum for states
UENUM() enum class EMyState : uint8 { Idle, Walking, Attacking };
// Define an enum for variant data
UENUM() enum class EMyVar : uint8 { ShouldAttack };
// Create states with transitions
UCSTMachine* machine = createObjectAtRuntime<UCSTMachine>(this, [this](UCSTMachine* m) {
m->init<EMyState>(FName("Combat"), {
SMT_NEW_STATE(EMyState::Idle, {
// action when entering Idle
},
SMT_BOOL_TRANSITION(EMyState::Attacking, EMyVar::ShouldAttack, true)
),
SMT_NEW_STATE(EMyState::Attacking, {
// action when entering Attacking
m_->set(EMyVar::ShouldAttack, false);
},
SMT_AUTO_TRANSITION(EMyState::Idle)
)
});
});
// Trigger a transition
machine->write(EMyVar::ShouldAttack, true);
// Check current state
if (machine->statusIs(EMyState::Attacking)) { /* ... */ }
// Reset
machine->reset();
// Move all state machines of a family on an actor
StateMachineUtility::moveOnAllSimpleStateMachine(myActor, CSTMachineFamillyName::CNAME_STM_ANIMATION_FAMILLY);