godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.07k stars 21.14k forks source link

Relative Z indexes do not carry through to scripts #45416

Open CitrusWire opened 3 years ago

CitrusWire commented 3 years ago

Godot version: 3.2.3

OS/device including version: Win 7

Issue description: Relative Z-Indexes do not carry through to stand-alone script functions that are called from a parent. This despite the fact that both the parent and the script have (default to) is_z_relative()== true`

Steps to reproduce: Parent scene: -> Background sprite (z-index 0) -> A scene (z-index 100) with a script attached calls a stand alone script that has a _draw() call in it. That draw call will be placed underneath the background.

Minimal reproduction project:

Will produce if this is confirmed as a bug

Calinou commented 3 years ago

@CitrusWire I don't understand exactly what's going on based on your description. Could you upload a minimal reproduction project, please?

CitrusWire commented 3 years ago

Scene (a) has a script which calls Script (D). D calls the _draw() method and draws something onto screen. That something is below the background(Z), despite the fact that everything else in Scene (a) correctly draws on top of background(Z).

Zireael07 commented 3 years ago

In that case, I can confirm that _draw() doesn't take relative z into account (I ran into it once, before 3.2.3)

meheleventyone commented 2 years ago

https://user-images.githubusercontent.com/5731661/140613784-2b983964-b135-4b40-93da-a7133c6d7069.mp4

I've got a fuller explanation of how I'm seeing this issue in my small project in this video.

The fundamental issue is that there is no easy way, short of manually walking up the tree and adding up the z_index values to get the relative z depth in script. Even when chains of nodes all have Z is Relative set as true. Looking through the current implementation it seems that relative z is pretty implicit so maybe a get_relative_z method would be a good addition to Node2D similar to local/global transforms.