How to duplicate an AnimationPlayer in Script?

Godot Version

4.2.1

Question

@onready var animationPlayer: AnimationPlayer = $AnimationPlayer

func _ready():
	var testPlayer=animationPlayer.duplicate(15)
	testPlayer.play("Attack")

I need to duplicate my animation player to prevent a reference of the original one. When I try to play the animation, nothing happens. The original one has the animation, it seems the duplicated one has none. Has anyone an idea how to really duplicate an animation player?

You need to add the duplicate to the tree first. :wink:

@onready var animationPlayer: AnimationPlayer = $AnimationPlayer

func _ready():
    var testPlayer = animationPlayer.duplicate()
    add_child(testPlayer)
    testPlayer.play("Attack")
1 Like

Hi. Thanks, you are right, but I already did and it is still not working. I can see it in the tree in remote, but the animation is not running when called though. This is strange.

Solved. I overwrote mit AnimationPlayer with the one of a parent class. Stupid.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.