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

How to reset a Rive animation? #51

Open
tomkail opened this issue May 13, 2024 · 6 comments
Open

How to reset a Rive animation? #51

tomkail opened this issue May 13, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@tomkail
Copy link

tomkail commented May 13, 2024

Hi! The docs don't seem to show a way to reset a Rive animation to the default state (including state machines etc). What is the correct way to do this?

@abethke
Copy link

abethke commented Jun 4, 2024

Have you tried turning it off and on again? Disable and then re-enable the related GameObject? It's hacky but it should work

@tomkail
Copy link
Author

tomkail commented Jun 4, 2024 via email

@abethke
Copy link

abethke commented Jun 4, 2024

I'm just another dev killing time while waiting for anyone to respond to my own ticket ;)

In my usecase the Rive animation just loops infinitely so I've not looked for a more elegant way to restart it.

@damzobridge
Copy link
Contributor

Hi Tom,

Could you give me a bit more detail about what you're trying to achieve? If you're looking to adjust the playback speed of your animations, you can use the advance() method on your State Machine instance. For instance, to double the speed, you can multiply elapsedSeconds by 2, like so: stateMachine.advance(elapsedSeconds * 2);.

However, since you're more likely referring to resetting your state machine back to its initial state. The recommended way to do this is to coordinate this within your rive file, and control the different changes to the state machine in Unity using inputs.

For example, in your rive file (in the rive editor), you could add a trigger input such as onReset and make it so that when that is fired, the state machine returns to its initial state.

You can then fire this trigger in unity and the animation will reset.

Working with rive files is a bit different from working with plain animations in that Rive files don't just hold animations, they also contain behaviours. A lot of the things you would usually manually coordinate in Unity in terms of timing animations, for example, can be handled within the Rive file itself, so all you need to worry about in Unity is changing inputs and responding to events. We're working on a lot more examples that illustrate this a bit more.

@tomkail
Copy link
Author

tomkail commented Jun 6, 2024 via email

@damzobridge
Copy link
Contributor

Ohh understood. Looks like this is available in some of our other runtime packages, but not currently in the Unity package.

We'll look into getting this added! Thanks for bringing it up, in the meantime, the unloading/loading approach you've mentioned is the alternative workaround if updating the rive file to add a reset trigger isn't an option.

@HayesGordon HayesGordon added the enhancement New feature or request label Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants