Inputs
Control graphic state and state machine transitions (legacy)
We strongly recommend controlling your Rive file through Data Binding, rather than Inputs.
For more information on creating Inputs in Rive, please refer to: 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 nested artboards at runtime, see Nested Inputs below.
Examples
Inputs
The web runtime provides an onLoad
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.
We use the 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
Examples
Inputs
The web runtime provides an onLoad
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.
We use the 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
Example
Inputs
The react runtime provides a useStateMachineInput
hook to make the process of retrieving a state machine input much simpler than that of the basic web runtime.
Inputs
With the React Native runtime, most methods/triggers are available on the ref of the Rive
component, including setting input values/triggering for state machines. In this case, there is no need to acquire an instance of an input. Simply set the input state from the Rive ref
or fire an input state.
See the React Native API’s to learn more about the parameters for .setInputState()
and .fireState()
Inputs
State machine controllers are used to retrieve a state machine’s inputs which can then be used to interact with, and drive the state of a state machine.
State machine controllers require a reference to an artboard when being instantiated. The RiveAnimation
widget provides a callback onInit(Artboard artboard)
that is called when the Rive file has loaded and is initialized for playback:
In the onInit
callback, you can create an instance of a StateMachineController
and then retrieve the inputs you’re interested in by their name. Specific inputs can be retrieved using findInput()
or all inputs with the inputs
property.
In the above snippet, the bump
input is retrieved, which is an SMITrigger
. This type of input has a fire()
method to activate the trigger.
In the complete example above, every time the RiveAnimation
is tapped, it fires the bump
input trigger and the state machine reacts appropriately.
Note: There are two other state machine input types to be aware of as well: SMIBool
and SMINumber
. These both have a value
property that can get and set the value.
Inputs
Setting input values for state machines goes through the RiveViewModel
instantiated in the View class.
.setInput()
inputName
(String) - Name of the input on a state machine to set a value forvalue
(Bool, Float, or Double) - value to set for the associatedinputName
triggerInput()
inputName
(String) - Name of the input on a state machine to trigger
Inputs
Just like other methods within the rive-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 Nested Artboards at runtime. These inputs are not on the main artboard but on a nested artboard. 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 nested artboards are marked as exported in the editor to access them at runtime:
You can go as many nested artboards deep as needed. For example, the Volume Molecule artboard shown above has two nested artboards with the following unique hierarchy names:
Volume Component
FX Component
Once you go more than one nested artboard deep the path will be a /
separated string of the unique hierarchy names.
If you load in the Menu artboard at runtime, and want to get/set an input on the 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)
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)
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)
To set the Volume input for the above example:
All options:
setInputStateAtPath(inputName: string, value: boolean | number, path: string)
fireStateAtPath(inputName: string, path: string)
To set the Volume input for the above example:
All options:
getBoolInput(name, path)
getTriggerInput(name, path)
getNumberInput(name, path)
To set the Volume input for the above example:
All options:
setInput(_ inputName, value: value, path)
wherevalue
can be aBool
,Double
, orFloat
triggerInput(_ inputName, path: path)
To set the Volume input for the above example:
All options on RiveAnimationView
:
setNumberStateAtPath(inputName: String, value: Float, path: String)
setBooleanStateAtPath(inputName: String, value: Boolean, path: String)
fireStateAtPath(inputName: String, path: String)
All options on RiveFileController
:
setNumberStateAtPath(inputName: String, value: Float, path: String)
setBooleanStateAtPath(inputName: String, value: Boolean, path: String)
fireStateAtPath(inputName: String, path: String)
To set the Volume input from the above example:
All options:
void SetNumberInputStateAtPath(string inputName, float value, string path)
float? GetNumberInputStateAtPath(string inputName, string path)
void SetBooleanInputStateAtPath(string inputName, bool value, string path)
bool? GetBooleanInputStateAtPath(string inputName, string path)
void FireInputStateAtPath(string inputName, string path)