Hey there,
i have a layered character with a ton of animations.
The Layers of my Character are all childs to Node2D and are animated via animationPlayer and animationTree, everything is find, except that on some animations there is the need to change the sorting order in specific frames...
As Example you have a Char with two layers and in the walk animation layer 1 is below layer 0... only in frame 4 of 6 of the walk animation the layer1 needs to be on top of layer 0
Is this possible in godot and if it IS possible than how?

As i understood the z-index of all my sprites inside my node2d is not only the z-index inside the parent but for all the nodes and stuff in my scene... or am i wrong with this?

Just for information on anyone that wants to do a similar thing, i created a function in the parent node, that contains all the sprites, that i call in my animation on a key in a method track

since it is only one specific sprite that needs the function only has one parameter with the target sorting order for the sprite.
in the function i simply call: self.move_child(new_order_pos)

maybe that helps someone out there 🙂

3 years later

Hey! I have made some code to do this. For anyone that still needs this. It works by settings the names of which nodes to move in a list. Hope this helps!

extends AnimationPlayer

@export var Sprites: Node2D

func _move_nodes_to_back(nodes):
if Sprites == null:
return

# Insert at the start, maintaining order
for i in range(nodes.size()):
	var name = nodes[i]
	var node = Sprites.get_node_or_null(name)
	if node:
		Sprites.move_child(node, i)

func _move_nodes_to_front(nodes):
if Sprites == null:
return

for name in nodes:
	var node = Sprites.get_node_or_null(name)
	if node:
		Sprites.move_child(node, Sprites.get_child_count() - 1)

PUBLIC: Call these from AnimationPlayer keyframes

func face_left():
_move_nodes_to_back(["Weapon", "AttackParticle"])
_move_nodes_to_front(["ArmRight", "ArmLeft"])

func face_up():
_move_nodes_to_back(["Weapon", "ArmLeft", "ArmRight", "AttackParticle"])

func face_right():
_move_nodes_to_front(["ArmLeft", "ArmRight", "Weapon", "AttackParticle"])

func face_down():
_move_nodes_to_front(["ArmLeft", "ArmRight", "Weapon", "AttackParticle"])