We strongly recommend controlling your Rive file through Data
Binding, rather than Inputs.
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.
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.Trigger
which has afire()
functionStateMachineInputType.Number
which has avalue
number property where you canget
/set
the valueStateMachineInputType.Boolean
which has avalue
boolean property where you canget
/set
the 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
- Use the artboard’s unique hierarchy name, not the artboard’s name.
- Do not include the name of the main artboard. In the example above, the path is
Volume Molecule
, notMenu/Volume Molecule
. - Ensure the components are marked as exported in the editor to access them at runtime:
Volume Component
FX 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
Do not use
/
in the name for your components, as that will break the search
functionality at runtime.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)