#Help! I don't know how to reset animations once they've played

1 messages · Page 1 of 1 (latest)

flint lantern
#

Okay so, what I'm trying to do effectively is:

  • I have three looping idle animations
  • I want to detect when the currently playing idle animation has finished, pick a new one at random, and play it, on and on, forever, until I make my character walk or do something else.
    The problem:
  • if the animations are looping animations, they reset properly the way I want, but they never send a signal saying they are "done" so I can't trigger the code to select and play a different random animation
  • if the animations are not looping animations the signal does work and my code will pick a new animation to play at random; however, once an animation reaches the end of its track it stays there frozen forever with no way to reset it

How do I go about achieving my use case?

#

For reference, my code:

median plaza
#

You have the animation_started signal in AnimationMixer

flint lantern
#

I think that just fires a signal when an animation begins playing though, doesn't it?

#

like I don't think it can be used to set an animation that's played back to frame 0

dull torrent
#

Hi! I am not too familiar with the animation system, but a search through the documentation showed that this is probably what you want:
https://docs.godotengine.org/en/stable/classes/class_animationnodetimeseek.html
https://docs.godotengine.org/en/stable/tutorials/animation/animation_tree.html#timeseek

flint lantern
#

I'll give that a try, thank you

left gulch
#

Yeah, I ran into this issue too and it's more of a godot 4 problem than godot 3 because you can get that actual callback when it completes a loop. How I manage to fix this is to just keep track of the timing in my code when the animation is played then compare it in the update loop.

#

You can also add method calls in the animation clip itself, but I notice they aren't that consistent if you have some sort of blending? Need to test it out more

flint lantern
flint lantern
left gulch
flint lantern
#

ah okay, do you remember which property I grab to find that info? for duration

left gulch
#
flint lantern
#

ahh, gotcha okay

left gulch
#

one other bandaid of an idea is just have an idle (or any loop animation) that goes into a similar idle, back and forth

#

it's stupid but was something I saw online lol

flint lantern
#

yeah I'd considered just chaining them together into a single long looping animation

thin kayak
#

My opinion would be to use a state machine node, and not a transition node. In the state machine node put in all three idles, add transition type "at end" connecting all three in a circle. Don't have any connected to the 'end' node

And you're done

Essentially it'll play one idle animation, and once it's done move on to the next one, and once it's done move on to the next one, and keep cycling through the circle. You'll be able to add a blend time to the transition too for a smooth change between each.

No script or code needed, seems like the easiest solution?

flint lantern
#

I tried state machine a bit but found it kind of intimidating lol

thin kayak
#

State machine is a.fsme.changer. it can save you hundreds of lines of code and from micro managing your animations. In particular, using a state machine with the expression Field for controlling changes for your base movement needs, and then having that nested in a blend tree as a base, where one shot nodes can Interrupt it.

My GitHub has a soulslike template which has a pretty robust animation setup. Feel free to download the project, see how it works and steal ally ideas.

Anyway back to your question.

No, not bi directional in your case. For just shuffling through idles endlessly, you'd set your idles to not loop in the animation player., (so they can 'end') And in the state machine node connect transitions set to switch 'at end'
Start to idle 1.
Idle 1 to idle 2
Idle 2 to idle 3
Idle 3 to idle 1

Set on each transition a .2 blend time

And that should do it. A gentle cycle between your idles, forever, ready to be interpreted by other nodes in your blend tree.

Generally I wouldn't do the walk the way you did here either. I'd do it as part of another sub state machine.

... This is sounding complex. It's way easier to see. Consider strongly checking out the cats soulslike template in my GitHub. And just investigate the 'movement' node in the tree.

#

It might be called 'WRISA'? Since the single node handles Walk Run Idle Strafe and Airborne. Basically any movement that needs to loop endlessly