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.
Inputs
Just like other methods within therive-android runtime, use the view to set values on a state machine input. In this case, there is no need to grab references to state machine input instances to set values.
There are 3 different methods to set input values or trigger inputs for number, boolean, and trigger inputs respectively:
.setNumberState(stateMachineName: String, inputName: String, value: Float).setBooleanState(stateMachineName: String, inputName: String, value: Boolean).fireState(stateMachineName: String, inputName: String)
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
To set the Volume input for the above example:
RiveAnimationView:
setNumberStateAtPath(inputName: String, value: Float, path: String)setBooleanStateAtPath(inputName: String, value: Boolean, path: String)fireStateAtPath(inputName: String, path: String)
RiveFileController:
setNumberStateAtPath(inputName: String, value: Float, path: String)setBooleanStateAtPath(inputName: String, value: Boolean, path: String)fireStateAtPath(inputName: String, path: String)