✅ Solved: Data Binding + Enum runtime control
Hi there,
I have a rev file from my animator with data bindings (attached), and I am trying to control it from my react runtime.
gensona.revIn code, I am able to successfully use the triggers to control the animation, but when it comes to the mouth movements (enum), I am successfully triggering the enum change, but it is not playing the mouth movements visually. I am following the data-binding documentation: https://rive.app/docs/runtimes/data-binding, but not sure what is wrong. The state changes seem to work within the Rive Editor, but just not the runtime. I’m wondering if the issue is within my code, the runtime, or the rev file. Appreciate any pointers!
Here’s my code:
// Initialize Rive animation
const { rive, RiveComponent } = useRive({
src: '/rive-files/gensona.riv',
stateMachines: ['State Machine [main]', 'State Machine [hello demo]'],
autoplay: true,
autoBind: true,
onLoad: () => {
console.log('Rive animation loaded');
}
});
// Update Rive animation when mouthState changes (lip sync via data binding)
useEffect(() => {
if (mouthEnum && rive) {
try {
// Set the mouth shape directly using the string value
mouthEnum.value = mouthState;
} catch (error) {
console.error('Error setting mouth enum value:', error);
}
} else if (!mouthEnum && rive?.viewModelInstance) {
// Try to get the enum again if it's not set
const enum_ = rive.viewModelInstance.enum('Mouth');
if (enum_) {
setMouthEnum(enum_);
try {
enum_.value = mouthState;
} catch (error) {
console.error('Error setting enum value on retry:', error);
}
}
}
}, [mouthState, mouthEnum, rive]);