How to Drive Rive Character Mood States (idle, happy, wave, loading) from App State
By the Charmotion team · Updated · How we write guides

Expose one number input, mood, in the Rive character's state machine, then let app logic write to it whenever app state changes. The web runtime finds the input by name and sets its value. Give each mood its own number, such as idle 0, happy 1, wave 2 and loading 5, and return to idle when a moment ends.
Key takeaways
- Expose a number input named mood in the state machine and set it from app code.
- Map each app state to one mood number in a single table, and write only when the value changes.
- Characters have no one-shot triggers, so show a success with happy and an error with sad.
- Return to idle yourself when the moment ends, using the length of that clip.
- Use Data Binding when app code needs typed properties, and check the release notes for your runtime version.
What are Rive state machine inputs?
A Rive state machine chooses which animation plays based on inputs that your app can read and change while it runs. There are three input types: number (a float value), boolean (true or false) and trigger (a one-shot signal). The Rive help documentation says state changes can be driven by setting boolean or number inputs, or by firing triggers.
Inputs are found by name. In the web runtime you list a state machine's inputs with stateMachineInputs and the state machine name, then pick the one you need by its name. Number and boolean inputs expose a value property that you read and set, and trigger inputs are fired by calling a method on them.
const inputs = rive.stateMachineInputs('CharacterStateMachine');
const mood = inputs.find(function (input) { return input.name === 'mood'; });
mood.value = 1;Here rive is the instance your runtime created for the .riv file. Check the load code in the docs for your runtime version, because package names and APIs change between releases. If you are new to the editor, the Rive tutorial for beginners covers building the state machine first.
Boolean inputs suit two-state flags such as isActive or isHovered. Triggers suit one-shot events such as a tap or a reset. Number inputs suit anything with several levels, which is why they fit a set of moods.
How to control Rive character mood states dynamically from app logic?
Use one mapping table in the app and one setter. The table turns an app state into a mood name, and the setter writes that mood's number to the input. It writes only when the value changes, so your code does not push the same value on every render.
const MOODS = { idle: 0, happy: 1, wave: 2, thinking: 3, sad: 4, loading: 5, listening: 6, talking: 7, sleeping: 8, attention: 9 };
let lastMood = -1;
let moodToken = 0;
function setMood(name) {
const value = MOODS[name];
if (value === undefined || value === lastMood) return;
lastMood = value;
moodToken += 1;
mood.value = value;
}The mood variable is the input you looked up in the previous section. Call setMood where app state changes, such as a network callback or a route change, not inside a render loop.
| App state | Mood | Number |
|---|---|---|
| Screen idle, nothing pending | idle | 0 |
| Request sent, waiting | loading | 5 |
| Save succeeded | happy | 1 |
| Save failed | sad | 4 |
| First-run greeting | wave | 2 |
| Voice assistant is listening | listening | 6 |
Only the moods you picked when creating a character are in its file, so pick wave and loading before you export if your screens use them. Plan the set around the states your screens actually need.
Should you use a state machine input or Data Binding?
Both approaches change the same character. A state machine number input is one value that you set by name. Data Binding exposes typed properties through a ViewModel that the file defines, and app code reads and writes those values. Rive's property types include Number, String, Boolean, Color, Enum, Trigger, Image, nested ViewModel and List.
| Approach | What it is | Good for | Watch for |
|---|---|---|---|
| State machine number input | A number named in the state machine | One value that app code sets by name | The name must match exactly, and timing is yours |
| Data Binding number property | A typed ViewModel property | Shared typed values, nested models and lists | Setup depends on the runtime version |
Runtime support differs by version. In the Flutter runtime, data binding happens when a RiveWidgetController is created, and the separate dataBind call was removed in 0.15.0, which needs Flutter 3.32.0 or later. In the Apple runtime, authored default instances bind automatically from v6.28.0, and DataBind is deprecated. The React Native hook useViewModelInstance needs @rive-app/react-native 0.4.18 or later for its async option. Check your runtime's release notes before you choose.
For Flutter specifics, see how to add animation to a Flutter app.
How do you show a success or an error when there is no trigger?
A trigger fires once and the state machine moves on. A number is a level: it stays where you set it until you set it again. That means the app, not the file, decides when a reaction ends.
For a character without a one-shot trigger for success or error, map the result to a mood. A success shows happy, and an error shows sad. Hold the mood for the length of the moment, then return to idle. Hold times should match the clip length of the animation you actually use.
function holdThen(name, ms) {
setMood(name);
const token = moodToken;
setTimeout(function () {
if (token === moodToken) setMood('idle');
}, ms);
}
async function saveProfile(data) {
setMood('loading');
try {
await api.save(data);
holdThen('happy', 1600);
} catch (error) {
holdThen('sad', 3000);
}
}The api object is a placeholder for your own client. The loading state stays on until the request settles, so a slow network shows the loading mood instead of a frozen idle character. For loading screens in general, see how to add a loading animation to an app or website.
How do you return to idle without flicker or race conditions?
Most glitches come from timers that fire after a newer state has started. The setMood function in this guide bumps a counter each time it writes a new value. A timer returns to idle only if the counter has not moved since the timer was set, so a late timeout cannot override a newer loading or error state.
- Write the mood only when its number changes, as setMood does.
- Keep one token for the whole mood sequence, and check it in every timer.
- When two events land close together, let an error win over a success.
Moods blend into each other, so rapid switching looks like a smear rather than a cut. Debounce noisy sources such as typing or scroll events, and set only the mood the user needs to see. Trigger-driven apps often add a separate reset path, but a number input works the same way with a timer and a token.
What mood numbers does a Charmotion character use?
A Charmotion character file uses the mood input described above, and the numbers are fixed. Moods blend into each other, so a change from one mood to another eases between poses. The table lists the clip length each mood runs for.
| Mood | Number | Clip length |
|---|---|---|
| idle | 0 | 4.0 s breathing and blinking loop |
| happy | 1 | 1.6 s |
| wave | 2 | 3.0 s |
| thinking | 3 | 2.4 s |
| sad | 4 | 3.0 s |
| loading | 5 | 1.2 s |
| listening | 6 | 3.0 s |
| talking | 7 | 1.6 s |
| sleeping | 8 | 4.0 s |
| attention | 9 | 1.4 s |
The file has three state machines. CharacterViewModelMachine holds a number property named mood for Data Binding, and CharacterStateMachine holds a number input named mood. LaunchStateMachine appears only when launch was picked, and it plays launch once and then idle. A boolean named accents hides the small accents such as Z z z while sleeping, thinking dots, the exclamation mark for attention and sparkles when happy. Accents are on by default.
If you would rather not wire these states by hand, Charmotion creates a character file with this mood input from one character image at /app/create.
How to drive Rive character mood states from app state
- Confirm the mood input. Check that the state machine has a number input named mood, or a number property named mood in the ViewModel, before writing any app code.
- Look up the input by name. Call stateMachineInputs with the state machine name, find the input whose name is mood, and check that it exists before you set it.
- Map app states to moods. Write one table from app states such as idle, loading, success and error to mood names, and keep the numbers in that table only.
- Write a setter that updates on change. Store the last value and write mood.value only when the number changes, and bump a token on each write.
- Hold moments and return to idle. Use a timer that checks the token so a late timeout cannot override a newer mood, and return to idle when the clip has finished.
- Test every mood in a preview. Step through each app state and confirm the right clip plays, including the loading, success and error paths.
Frequently asked questions
Does the character change mood instantly?
No. Moods blend into each other, so a change from idle to happy eases from one pose to the next instead of cutting. Rapid changes look like a smear, so debounce noisy sources in app code and set only the mood the user needs to see.
Do I need Data Binding to change a mood?
No. Setting the number input named mood is enough, as the web sample shows. Data Binding helps when app code should read and write typed properties from a shared ViewModel, and it depends on the runtime version, so check the release notes for your platform before you rely on it.
Why does my mood not change?
Check four things: the state machine name matches exactly, the input is named mood, the value you set is a number rather than a string, and the mood's animation was picked when the character was created. A misspelled name returns no input, so guard for undefined before you set the value.
Should the app or the Rive file decide the mood?
The app. Keep app state as the source of truth and write the mood from it. The file shows the states it contains, but it cannot know whether a request failed or a user is waiting, so keep that logic in one place in your code.
Sources
- State machine inputs, Rive Help
- Rive web runtime parameters, Rive
- Data binding property types, Rive
- Flutter migration guide, Rive
- Rive React Native runtime, Rive
- Rive Flutter GenUI integration, Very Good Ventures