Z-index of autoload'ed Node2D?

Godot Version

using Godot 4.2


Hi there,

I have a gdscript that extends Node2D and is configured to autoload,
problem is I’d like to change this node’s z-index. I believe I should do this through the inspector (similar question) but how?

When I select the gdscript file the inspector detects the Resource.

Context: I’m using GodotDebugDraw to render debug arrows. My shapes are “hidden” below my tilemap. I think changing the z-index of the autoload would make sure the draw call are rendered above all my other objects.

You should be able to set a z index on the autoload via script. I’d say go to the autoload script, add the _ready method to it and set the z index there

1 Like

Adding to what @struhy_xd already said: The plugin seems to already do that - so unlike your TileMap has a z index above 1000, this is likely not the source of your problem.


Thanks for the quick answer @struhy_xd! And thanks for digging deeper @njamster I missed that line :man_facepalming:

My objects are rendered in a CanvasLayer, which seems to be the issue: anything inside that canvas layer is rendered above the DebugShapes.

I have a rough understanding of the whole rendering system with RenderingServers, etc,

(1) Is there a quick way to create a dynamic CanvasLayer above every other canvas layer and attach my DebugDraw2D object to that layer?

(2) To make that system more reliable, do you have a rough idea of the API calls to create a CanvasItem for a given CanvasLayer, and set that CanvasItem above everything else in that layer?

(I would create a system that takes the current layer on call to DebugDraw2D.some_shape and render the shape in that layer).