how to make animation loop when i use state machine?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bgegg

when i press up key,walk animation played.but,it only once.
how to set animation loop?
https://i.imgur.com/6yi6ljI.mp4

   extends KinematicBody
    var state

func _ready():
	state = $"Scene Root/AnimationTree".get("parameters/playback")
	state.start("death")
	
func _process(delta):
	if Input.is_key_pressed(KEY_UP):
		state.travel("walk")
	else:
		state.travel("death")
:bust_in_silhouette: Reply From: usurun

You have to press the button loop, inside the AnimationPlayer

thank

Even if it is enabled in animationplayer, it will not loop when the project is executed

bgegg | 2019-10-26 22:34

Try stopping the animations before playing a new one.

AnimationPlayerNode.Stop()
AnimationPlayerNode.Play("AnimationName")

Also it is inside a function that is looping, which means that it is being started many times. Try making something so it just runs once.

usurun | 2019-10-26 22:59

Thank you
State machine doesn’t seem to be necessary
Is operating the animation player directly the same as the state machine?

bgegg | 2019-10-28 07:51

:bust_in_silhouette: Reply From: AMixOfGeekStuff

Someone on discord told me: if you’re using Blender for 3d animations, you have to open your character in blender, add “-loop” to the end of every animation action you want to loop (don’t add the quotation marks, though), and then re-import it into Godot. Now they’ll loop properly.

Note: you can’t just rename the animations within Godot and add -loop. And you can’t just turn on the loop button for the animation within Godot (even though it’s the intuitive thing to do). You have to rename the animations in Blender and re-import everything afaik :confused: Tedious.

I hope Godot simplifies this, as well as the whole importing from blender process because it’s tedious and also causing other unnecessary problems imo :confused:

And if you’re not using blender then… Hopefully someone else knows the answer?

That is indeed the case. Your looping animations need to have the suffix “-loop” within Blender (and probably any other content creation tool).

stormreaver | 2023-04-01 14:21