play multiple AnimationPlayers for 1 Sprite at the same time (not after each other)

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

I am new to Godot and I have searched for this question on reddit and here, but the answers are not working for me.

I have separated my player’s body parts (bodies, heads, main_hands, second_hands) into different frames but they are in one texture. The reason I have done this is that I want each body part to play a different animation based on the situation. For example when the player is holding a staff and running I want MainHandAnimation to show hold animation while the rest of the body parts show run animation.

To solve this I made a Sprite with 4 different AnimationPlayer nodes as its children. Each AnimationPlayer is for one body part only. In the player’s script I play animations after each other but instead of showing all the body parts at once the sprite only shows the lowest AnimationPlayer

For example in a structure like this:

----Area2D
-------- CollisionShape2D
-------- Sprite
------------ BodyAnimation (=AnimationPlayer)
------------ SecondHandAnimation (=AnimationPlayer)
------------ HeadAnimation (=AnimationPlayer)
------------ MainHandAnimation (=AnimationPlayer)

Running this code will only Show MainHandAnimation and not the other ones.

$Sprite/HeadAnimation.play("walk")
$Sprite/BodyAnimation.play("walk")
$Sprite/MainHandAnimation.play("hold" if is_holding else "walk")
$Sprite/SecondHandAnimation.play("walk")

The frames have transparent background so they should be shown on top of each other without any problems.

:bust_in_silhouette: Reply From: Gabriel

As far as I know to solve your problem you would need 4 Sprite nodes, even if all 4 of them would have the same texture. Then you would use each AnimationPlayer node to animate each Sprite. It seams that the way you are doing it now one AnimationPlayer is overriding the other since they are changing the same Sprite.

This video may be of help: How to Make a Run Cycle Using Cutout Animations in Godot 3.0

I thought the way you are describing is the correct way to do it but the answer to this question mislead me. I don’t know how it is accepted as the best answer and has 2 upvotes! Thanks for the clarification and the video. They were very helpful. I’ll wait a day and if no better answers were given, I’ll choose this as the best answer.

R0AR | 2019-10-03 05:37

Hi, ROAR. That answer is correct for that question because in that case each AnimationPlayer will animate different properties. One of them will animate the “frame” property (for the movement animation) and the other will animate the “visible” property (for the blinking effect when the character takes damage). In your case all AnimationPlayer nodes change the same property of the same node. That’s why it did not work.

Gabriel | 2019-10-03 13:56

Oh… That makes sense. Thank you so much!

R0AR | 2019-10-03 15:06