Using an AnimationPlayer in an instanced scene animates the wrong sprite

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

I have created a scene for a door, which has a hook for a signal when a user is trying to open the door. When this is called, it checks to see if the door the player is trying to open is the current one, and if so, it calls $AnimationPlayer.play("Open").

Several print_debug calls confirm it is making the call to play on the correct instance, but the animation actually occurs on the other instance.

The code that handles the entering_door signal can be found below:

func _on_Player_entering_door(door):
	print_debug("player entering door " + door.name)
	if self.name.nocasecmp_to(door.name) == 0:
		print_debug("starting animation for " + self.name)
		$AnimationPlayer.play("Open")

Is this normal behaviour? If so, how would one approach having an instanced scene that contains animations?

My idea behind this was to create a scene which will let me hook up a few signals and then have multiple doors in the parent scene that are all consistent and can be managed with one set of code etc.

Is it always the same door that opens no matter which door you are actually interacting with? Or is it always just the other door?

Eric Ellingson | 2019-07-28 17:33

Yes - the print_debug call will always say it is starting the animation for the correct instance, but it’s always the other sprite that actually animates

robthefivenine | 2019-07-28 17:34

What does your scene tree look like?

Eric Ellingson | 2019-07-28 17:35

This is the top level scene tree: top-level-tree.png - Google Drive

This is the scene tree of the Door scene: door-tree.png - Google Drive

robthefivenine | 2019-07-28 17:47

Would you be able to share the project?

Eric Ellingson | 2019-07-28 17:58

I have uploaded a copy here with the art work replaced with arbitrary shapes: https://drive.google.com/open?id=1Q9Gsr6hj8STzqBMjm9eRdsrSRUZhBnTT

You can move the blue square (Player) with the A and D keys, and then when in front of a door (the red blocks), if you hit the W key, it will begin the animation process after ~1 second and you’ll find the only one that animates is the one on the far right.

robthefivenine | 2019-07-28 18:38

@Eric Ellingson, I managed to find the cause of the bug. I have just posted an answer for it in case you’re interested in seeing the details (TLDR: the path to the sprite in the animation player was absolute instead of relative)

robthefivenine | 2019-07-28 19:09

:bust_in_silhouette: Reply From: robthefivenine

I managed to find the issue - it was the reference to the target sprite in the AnimationPlayer. Some how, it had an absolute path, rather than a relative one. After changing this to a relative path to the sprite that was being animated, it works now

Ok, but how did you do that ?

Athrosus | 2021-05-08 12:42

By double clicking the track name in the animation player and changing the path

robthefivenine | 2021-05-08 14:20

:bust_in_silhouette: Reply From: Pitayamax

I have came into similar problems. And my solution is make specific “Animation” in the “AnimationPlayer” local to scene.

In detail, click “Animation” button in the “AnimationPlayer editor”, and choose “Open in the Inspector”, then on the inspector panel, find “Resource”->“Local to Scene” and tick it.