Forum rules - please read before posting.

The best way to pause an animation at any time?

So I would like to stop an animation (several) exactly when I want it to happen, with a button.
What would be the best way to do this?

I followed the instructions here:
https://adventurecreator.org/forum/discussion/10395/pause-mechanim

Here you said to "attach this script (PauseAnimator.cs) to your Animator".
But how can I attach one script to one Animator?
I can only attach this to one GameObject. Or I don't know too much about Unity :(

So what I did was to make a Prefab from that GameObject (which is basically the animation with the Bird from the 2D tutorial, always running) and assign it to AC's Object: Call event.
Because I cannot directly assign a GameObject, with this assigned script.

And when I try to use AC's Object: Call event, I can't figure out which options to choose. I don't see the Pause or Resume part there.
I will attach the picture below.
https://ibb.co/W64gyQB

Maybe the answer is obvious, but I'm not that good at coding.

And one more question, why is the Resume speed still 0?

Thank you again!

Comments

  • Here you said to "attach this script (PauseAnimator.cs) to your Animator".

    I was referring to the same GameObject that the Animator component is attached to.

    If you're using the Object: Call event Action, the functions will need to be public - just add the public keyword to the front of both functions.

    This Action type can only affect scene objects when part of a scene-based ActionList, however. If you want to have an ActionList asset reference a scene object, or a scene-based ActionList reference a prefab, use the Object: Send message Action instead.

  • Thank you for your help!

    So I managed to pause the animation with Object: Send message where I set Message to send: Custom and Method name Pause/Resume.
    I also put GetComponent <Animator>().speed = 1f; at resume part in that script. So no 0f.

    I still don't understand how to use Object: Call event, since nothing happens when I use this part with Pause/Resume.

  • edited August 2023

    What kind of ActionList is the Object: Call event Action placed in, and what/where is the object you're having it affect?

    It's important to be sure to have this Action affect a GameObject that has the script as a component, rather than affect the script directly - even though it's technically possible.

    It's also the case that you can't have an asset affect a scene object this way, as the Constant ID system won't work with this Action. In this case, Object: Send message is the way to go.

  • Well, I tried with the** BirdAnims1_0(Prefab Asset**) from 2D Demo > Graphics > Sprites > Bird , with that script attached to it.

    So I guess I was wrong :D

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.