Quick answer: Godot 4 CanvasItem z_index set in code but draw order doesn't change? z_index applies relative to parent; reparent or use z_as_relative = false for absolute ordering.
Floating damage numbers spawn under the world layer despite setting z_index = 100.
Disable relative z
label.z_as_relative = false
label.z_index = 100Absolute z values ignore the parent's z; the label draws above everything globally.
Or reparent to a UI layer
For consistently-on-top floating UI, parent under a CanvasLayer with layer = 1. CanvasLayer ordering wins over z_index.
Verify with the visual debugger
Editor > Debug > Visible Collision Shapes. Helps spot ordering issues; works for canvas too.
“Godot's draw ordering has multiple axes. CanvasLayer beats z_index; z_index can be relative or absolute.”
Establish a layer convention: world = CanvasLayer 0, UI = 10, floating text = 20, modal = 100. The discipline prevents most ordering bugs.