AnimationPlayer animation not playing on different instances of the Scene

Godot Version

4.1.3

Question

I have a situation where AnimationPlayer seemingly does not activate its animation on different instances of the same scene.

I have a scene file with AnimationPlayer and a script instance attached to it. The player interacting this scene would enable an animation. But when creating multiple instances of the scene, the animation only plays on the first interacted instance and the rest is ignored. What could be the cause?

Maybe others know the answer as-is, but I’d say a lot more info is needed about your exact setup (scene tree), the code that spawns, the code that starts animation, etc.

And why are you inheriting from AnimationPlayer?

Sure thing,

I’m trying to instance a scene, with its own script instance that allows interaction. But in my situation, it activates the animation on the first player interacted instance, and then interacting with the other instances won’t activate the animation.

I don’t believe it is a scripting problem, considering the first instance works as expected, and to my knowledge, duplicates should follow. But again I might be wrong:

@export var bounce_force = 675.0
@onready var animation = $AnimationPlayer
@onready var character : Player = $"../Player"

#Area2D signal to activate interaction
func _on_area_2d_area_entered(area):
	if area.get_parent() is Player:
		character.velocity.y += bounce_force

		animation.play("Spring")
		# AnimationPlayer line that's not emitting across instances
		# Only on first player interacted instance

This is scene file tree:

↓Jumppad (Type: StaticBody2D, Script: seen above)
	→CollisionShape2D
	→Sprite2D
	→AnimationPlayer
	↓Area2D
		→CollisionShape2D

There might something about instancing behavior I’m not informed of. If there’s something incorrect I’d like to know.

I only see one AnimationPlayer, where are the others?

Also if I may go back to the other question - why are you inheriting from AnimationPlayer? It’s just very unusual to inherit from AnimationPlayer node, so I’m curious what your goal/needs are to make you go in that direction.

Btw “area entered” is only emitted once. If the area1 that entered area2 stays within area2 (i.e. continues to intersect with it), the event will not be emitted again until area1 completely exits area2 and then re-enters again. Not sure if this is related at all, but just fyi.

Not sure what you are talking about, I am not inheriting from AnimationPlayer, the root node (Jumppad) is inheriting it, as you can see in the hierarchy. Neither are there two AnimationPlayer nodes

Yes, signal area_entered is emitted once after interaction, though can be emitted multiple times on the area entering, it IS a signal.

I can see the problem is not with the connected function, as the line character.velocity.y += bounce_force appears to run as expected across the instances. The problem is with animation.play("Spring"), as the animation does not play in its own instance, only on the first player interacted instance.
I’ve already said this in the included comments in code snippet for further info

		animation.play("Spring")
		# AnimationPlayer line that's not emitting across instances
		# Only on first player interacted instance

I believe this should work as intended with the scene and script instance, I might be missing some knowledge, which is why I’m eager to learn about this.

Rephrasing my question: AnimationPlayer animation not playing on different instances of the Scene, despite the Scene having it’s own script instance

Gotcha, I think it was a translation misundestandnig. You original post said “I have a tscn file inheriting AnimationPlayer”. The word ‘inherit’ means something very specific in programming. I see now that you meant your scene just has an AnimationPlayer.

So you’re saying that when Player enters multiple Area2Ds (each attached to a different Jumppad), and you add add a print() statement before animation.play, the statement prints, but only one of the animations plays?

Hmm. Did you check actual animation on each AnimationPlayer to make sure they don’t reference the same object or something?

Alright, I think it would be better to showcase this in video form:

This Youtube link showcases this issue.

As you can see, AnimationPlayer instancing is not working as intended, the animation is not playing on different instances of the Jumppad Scene.

Now my question is, how can this behavior be fixed?

Nice video, thanks.

Yep, exactly as I said - the animation IS playing when you you touch pad 2 and 3, but the Animation Player’s animation references the original pad, which is why original pad is animating.

Open AnimationPlayer on pad2, go to Animation window at the bottom, like here:

Screenshot 2023-12-29 at 11.30.57 PM

and for each animation track check which scene the frames are actually referencing. If you have call_method track, method on which object is it calling? You’ll find that your animations on pad2 are calling properties or methods on pad1. Same for pad3.

Correct, you are pointing to the right direction.

And see, this is the tricky part

I can’t open AnimationPlayer panel on Jumppad2 or Jumppad3 because they are instances, meaning they’re all the same in a way, same with Jumppad1. I can only see scene’s content by opening the scene in a separate scene tab

The Jumppad scene file instanced to another scene:
SceneInstancedInScene

The Jumppad scene file open in its tab:
scenetree

As you can see, I can’t access AnimationPlayer panel on different instances. Only in its tab, because updating one scene applies across all others, but my issue is the animation on different instances is not playing as intended, like in the video.

You sure can. Right-click on Jumppad2 and enable Editable Children.

That said, please show Animation tab for the original Jumppad scene, still want to see how AnimationPlayer is setup in that one.

Thank you for informing me on this knowledge, though not sure about editing children of a scene file instance, doesn’t seem intended and might break something.

But sure, here’s the animationplayer setup, there are two animations, idle:

Spring:

If you don’t mind, I’ll tell you my way of counteract this situation as came up with an approach. instead of using the same Jumppad instance in one scene, i’ll try to create multiple of them. Since the problem is with instancing the same jumppad scene more than once, I’ll create JumpadA.tscn, and JumppadB.tscn, and JumppadC.tscn, and instance them into my scenes.

Editing Children is indeed intended and won’t break anything. This is exactly the purpose of that feature - to change things specific to an instance of a common scene. For example, your general Enemy scene will have areas with collision shapes such as HitBox (the area that hits player) and HurtBox (the area that can be hit by player) and since not all enemies are same size, you will use Editable Children feature to resize these areas on specific instances of Enemy class.

So go ahead and enable it, then check your AnimationPlayer in each instance. I’m honestly not exactly sure why it’s not working for you, but you can also just add tracks to AnimationPlayer in code, that way it should for sure work fine.

Either solution is far better than having JumppadA, B, etc. imho.

Sometimes it’s as dumb as restarting Godot lol btw, have you tried that? I had the weirdest engine behavior that sometimes is solved with just restart. This behavior is indeed wild afaik.

Just had a thought: Editable Children is like overriding parent class methods in your child class, but for Editor configuration.