Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequential calls to ref.setInputState results in only the last one being updating in the animation. #265

Open
CoopCodes opened this issue Sep 18, 2024 · 2 comments

Comments

@CoopCodes
Copy link

Description

When using Rive with React Native, setting multiple input states sequentially does not work as expected. Only the last input change is reflected in the animation, ignoring previous input changes.

Provide a Repro

Here's a minimal code snippet that reproduces the issue:

MonsterRef.current?.setInputState(stateMachineName, "Many Teeth Mouth", true);
MonsterRef.current?.setInputState(stateMachineName, "Many Eyes", true);

In this example, only the "Many Eyes" input change is reflected in the animation, while the "Many Teeth Mouth" input is ignored.

A workaround using setTimeout and Promises works:

new Promise((resolve) => {
  setTimeout(() => {
    MonsterRef.current?.setInputState(stateMachineName, "Many Teeth Mouth", true)
    resolve(null);
  }, 50)
}).then(() => {
  setTimeout(() => {
    MonsterRef.current?.setInputState(stateMachineName, "Many Eyes", true);
  }, 50)
});

Expected behavior

When setting multiple input states sequentially, all input changes should be reflected in the animation, not just the last one.

Screenshots

N/A

Device & Versions (please complete the following information)

  • Device: Google Pixel 7 API 34, ran on Android Studio Device Manager (emulator) with Windows 11.
  • OS: Windows 11 Version 23H2
  • NPM Version: 10.8.1

Additional context

This is functionality for part of my app where you can customize your character, using several different body parts. The state machine has an input for each bodypart, the input is of type "trigger".
I have been able to work around this will a mess of Promises and setTimeouts, ensuring none run at the same time. But as my codebase grows I will not be able to keep this up.

@CoopCodes CoopCodes changed the title Sequential setInputState calls ignore all but last input Sequential calls to ref.setInputState results in only the last one being updating in the animation. Sep 18, 2024
@CoopCodes
Copy link
Author

UPDATE:
I tried a similar example with a smaller state machine in a different rive file, and it worked, seems to have to do with the state machine size...

Not working example State machine:
image

Smaller State machine:
image

Thanks!

@lancesnider
Copy link
Contributor

Hi Coop. Rather than trying to call the same Any State multiple times at once, I'd recommend using state machine layers: https://rive.app/community/doc/layers/docQI8guiwME. That way you can control the different areas separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants