Overview
TheRiveStateMachineInstance class represents a running instance of a state machine from your Rive file. State machines control animation states based on inputs and conditions, making them ideal for interactive experiences.
Creating State Machine Instances
From RiveArtboard
Using RiveModel
Using RiveViewModel
Advancing State Machines
Working with Inputs
State machines can have three types of inputs: booleans, numbers, and triggers.Accessing Inputs
Boolean Inputs
Number Inputs
Trigger Inputs
Using RiveViewModel for Inputs
State Changes
Track when states change in your state machine:Events
Handle events reported by the state machine:Touch/Pointer Interactions
State machines can respond to touch events:Basic Touch Events
Multi-touch Support
Use touch IDs for multi-touch interactions:Hit Results
| Result | Description |
|---|---|
none | Touch didn’t hit any interactive element |
hit | Touch hit an interactive element |
hitOpaque | Touch hit an opaque interactive element |
Layer Information
State Machine Name
Data Binding
Bind view model instances to state machines:Complete Example
SwiftUI State Machine with Inputs
Best Practices
Use state machines for interactive content
Use state machines for interactive content
State machines are ideal for buttons, toggles, hover effects, and any animation that responds to user input.
Check input existence before setting values
Check input existence before setting values
Always verify inputs exist to avoid runtime errors.
Handle events each frame
Handle events each frame
Process reported events immediately after advancing the state machine to ensure you don’t miss any events.
Use RiveViewModel for simplified input management
Use RiveViewModel for simplified input management
RiveViewModel provides a simpler API for setting inputs compared to working directly with state machine instances.Related
- Linear Animations - For timeline-based animations
- Artboards - Access state machines from artboards
- RiveViewModel - High-level state machine control