ZIndex not working in 2D

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

I have tried set_z_index() in code, and just setting the default z_index at the root of each individual scene which I will be instancing, on the assumption they will be instanced with that z_index.

But when my dagger node spawns an animated sprite (toonSmoke) with a z-index of 500 for the smoke, and 1000 for the dagger-the smoke always appears above the dagger.

if overlaps_target == true:
		var smoke:Node2D = resSmoke.instance()	
		smoke.position = self.position
		print("Dagger Z-Index: " + str(self.z_index))
		print("Smoke Z-Index: " + str(smoke.z_index))
		call_deferred("reparent_to_target",self, target)
		call_deferred("reparent_to_target",smoke, target)

my console outputs:

Dagger Z-Index: 1000
Smoke Z-Index: 500

But my smoke is above my dagger:

enter image description here

It seems to just order them in scene tree order, and doesn’t care about zindex.

With the information you provided it’s hardly possible to help you out. Can you upload an example project (as minimal as possible!) with the problem at hand?

njamster | 2020-09-20 21:28

:bust_in_silhouette: Reply From: indy2005

The sprite sub node had a separate higher z-Index…my fault