Controlling state machine inputs
Once the Rive file is loaded and instantiated, the state machine can be queried for inputs, and these input values can be set, and in the case of triggers, fired, all programmatically.Inputs can also be set on components at runtime, see Nested
Inputs below.
- Web
- React
- React Native
- Flutter
- Apple
- Android
Examples
Inputs
The web runtime provides anonLoad callback that’s run when the Rive file is loaded and ready for use. We use this callback to ensure that the state machine is instantiated before we query for inputs.stateMachineInputs function on the Rive object to retrieve the inputs. Each input will have a name and type. There are three types:StateMachineInputType.Triggerwhich has afire()functionStateMachineInputType.Numberwhich has avaluenumber property where you canget/setthe valueStateMachineInputType.Booleanwhich has avalueboolean property where you canget/setthe value
Nested Inputs
You can control the inputs of Components at runtime. These inputs are not on the main artboard but on a component. To set a nested input, you need to know the path where the input exists at an artboard level.Example
Volume ComponentFX Component
Once you go more than one component deep the path will be a
/ separated
string of the unique hierarchy names.FX Component artboard, the path will be Volume Molecule/FX Component
- Web
- React
- React Native
- Flutter
- Apple
- Android
- Unity
To set the Volume input for the above example:All options:
setNumberStateAtPath(inputName: string, value: number, path: string)setBooleanStateAtPath(inputName: string, value: boolean, path: string)fireStateAtPath(inputName: string, path: string)