Animating Multiple Instances - Guidance and Troubleshooting

Godot Version

4.3

Question

I am making a card game. I was hoping to be able to animate complex animations with multiple cards that are chosen dynamically. Decided to do some small testing in a separate project. I am unable to get two animations to play at the same time. I am happy to hear any general guidance as to how this might be achieved or any help with this current issue below:

Manager simply adds two card scenes and tries to get them both to move to the same spot.

func _ready() -> void:
	var newCard
	for i in range(0,2):
		newCard = cardPreload.instantiate()
		newCard.global_position = Vector2(100+900*i,200)
		$Hand.add_child(newCard)
		
		newCard.move()

My first goal was to get both cards to move from their positions to the same position. So, I tried

func move():
	track_set_key_value(0,0,self.position)
	$AnimationPlayer.play("move")

However, both cards follow the same path due to the same animation being used. Now I’m trying to create a new animation and have been unsuccessful. I’ve tried duplicating the “move” animation and manufacturing it in code:

func duplicateConstruction():
	var newAnim = $AnimationPlayer.get_animation("move").duplicate(true)
	newAnim.set_local_to_scene(true)
	
	newAnim.track_set_key_value(0,0,self.position)

func manufactureConstruction():
	var newAnim = Animation.new()
	
	newAnim.resource_local_to_scene = true
	newAnim.step = 0.1
	newAnim.length = 1
	
	newAnim.add_track(Animation.TYPE_VALUE)
	newAnim.track_set_path(0, str(get_path()) + ":position")
	newAnim.track_insert_key(0, 0.0, self.position)
	newAnim.track_insert_key(0, 1.0, Vector2(500,300))

and also playing it in two ways; using the existing library and creating a new library:

func playNewLibrary(newAnim):
	var newLibrary = AnimationLibrary.new()
	newLibrary.add_animation("newAnim", newAnim)
	$AnimationPlayer.add_animation_library("newAnim", newLibrary)
	$AnimationPlayer.play("newAnim")

func playReuseLibrary(newAnim):
	var library = $AnimationPlayer.get_animation_library("").add_animation("newAnim", newAnim)
	$AnimationPlayer.play("newAnim")

playNewLibrary() doesn’t seem to work. playReuseLibrary() will play the animation a third of the time and crash without an error message two thirds of the time. I have never gotten both cards to animate independently. The final project will require some way of creating intracate animations. So, tweening everything and writing everything in code isn’t preferable. However, I’m open to any guidance.

Thank you

I think it would be easier to use Tweens to animate here instead of changing the track of an AnimationPlayer. You can create intricate animations with a tween as well, it’s just that AnimationPlayer has a UI. A tween can do anything an AnimationPlayer can do.

If you still want to use AnimationPlayer, however, can you post the errors you get when the animation causes an error?

1 Like

Unfortunately, it crashes without any error dialogue, now. Pulling from my google history, I received the following error early in the process. I believe the code was nearly identical, but there is the possibility that this isn’t the case:

E 0:00:01:0453 make_animation_instance: Condition “!has_animation(p_name)” is true. <C++ Source> scene/animation/animation_mixer.cpp:1909 @ make_animation_instance()

Of course I also discovered a post that resolves the simultaneous animation issue, shortly after posting:

1 Like