Animation loop with a script

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

Hello, I have a simple script. When I press F1, my character play emotion animation. I want to loop animation forever. I can not use loop animation in AnimationPlayer because its just not working, so I want to make it by code. Model imported from
blender it loops in the editor but not loops in a game when key is pressed. Is stick on the last frame.

Any help please?

export(NodePath) var animator

onready var _anim_tree = get_node(animator)
func _physics_process(_delta):

if Input.is_action_just_pressed(“f1”):“emotion”)

Based on the name, I would expect_anim_treeto be an AnimationTree, but AnimationTree doesn’t have a play function. Can you post more details, maybe a screenshot of your SceneTree or your tscn file?

Why is AnimationPlayer “just not working?”

alexp | 2022-10-16 20:03

alexp thank you for your answer.

Code image
Screenshot by Lightshot

AnimatioPlayer image
Screenshot by Lightshot

I found the solution, I had to rename animation and add -loop at the end of the animation name, so then animation is looping. But Its weird, still I like code, and there is no way how to loop animation with a code?

satrebor | 2022-10-17 07:47

:bust_in_silhouette: Reply From: Wakatta
func _ready():
	anim.connect("animation_finished", self, "_animation_finished")

func _animation_finished(anim_name):
	if anim_name == "":