-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move z_index, z_as_relative and y_sort_enabled from Node2D
to CanvasItem
#68070
Move z_index, z_as_relative and y_sort_enabled from Node2D
to CanvasItem
#68070
Conversation
This would address godotengine/godot-proposals#839. I think last time we discussed this on Rocket.chat, @reduz raised the objection that would be confusing since it only impacts the render order, while in Controls you would expect the order in which items are laid on top of each other to impact input handling. So changing the Z Index on e.g. a Button to make it appear in front of another Button would be the misleading impression that it's the topmost button, and thus the one receiving the input, when it isn't. Someone also raises the same objection in that proposal and there's further discussion, to be assessed further. |
As I said in the chat, I think Controls should just have a configuration warning if their |
ac7c503
to
ad3f2a2
Compare
Accidently pushed the wrong branch :/ |
ee86002
to
ff9a61b
Compare
Rebased and added the configuration warning suggested by @KoBeWi to Controls with |
ff9a61b
to
a68f674
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation is ok.
I still think this is not a great idea, its very corner case and easy to work around, plus having to look for this in canvas item is a bit weird. But if you really want it this way, go ahead. |
@reduz To me it just makes a bit more sense there. Having a duplicated property both in Control and Node2D would be somewhat strange (regarding OOP, since the RS provides the functions for |
a68f674
to
b5e3eb8
Compare
This is not how you work around this now. You use the server API, for example (a 3.x version): extends Control
func _ready():
VisualServer.canvas_item_set_z_index(get_canvas_item(), 100)
I think it's not enough, definitely not just a property warning. It breaks several expectations for Control nodes, and hiding this fact so deep is not a good idea. |
You're right, the cleaner workaround would be to use the server API (just for reference, in 4.0 it can be achieved by using the respective RenderingServer methods) However, this has the disadvantage that it can't be done without a Script and as you said you're able to change the behavior of Control nodes, breaking several expectations without any warning.
Now after thinking about it, that might be true. Even for users which exactly know what they are doing it might be helpful to have a warning directly in the SceneTree to indicate that a Control behaves abnormally. (as mentioned above, this is also the problem with the server API workaround). |
Yep, I think we're on the same page. 🙃 Can you update the documentation though, as suggested? A note with basically the same content as the warning would be good to have in the documentation. |
b5e3eb8
to
0e9d10c
Compare
Supplemented the documentation with a note concerning |
0e9d10c
to
e84f45f
Compare
Thanks! |
This is major. Putting them into CanvasItem makes it so much easier for users to imagine and familiarize with the 2D rendering steps at a glance. Now CanvasItem can be really thought to be the 2D rendering node, while Node2D and Control are just different ways to shift the rendering around. |
I'm stoked on this!! I've often wanted to use z_index on a control node!! I've had a few use cases in the UI for my game ROTA. This will help me organize my project cleanly(: |
I like this idea! I've been adding Controls to Node2Ds just to get the ZIndex. Always worried it was a hack but did it anyways since it just works |
Currently editing a project that will MASSIVELY benefit from this <3 |
Is this potentially backportable to 3.x? I have a project that does NOT need Vulkan but needs this... |
While this is marked as a breaking change, I don't think it technically is. In a sense that it doesn't replace or reduce functionality, at least. So it's probably possible if anyone wants to do it. That said, you can already use this feature through scripts in 3.x. This is just a convenience change. |
That's exactly why I asked
Please tell me (or even better, document somewhere) how to achieve the same thing with Control nodes in 3.x without this change |
|
Thanks a lot, goes into my offline notes. This means I can fix my map without waiting for this PR to be backported <3 |
So, this is possible to backport. The limitation was merely artificial by design? |
I think it's more that the low-level implementation makes it unintentionally possible for any CanvasItem, but the feature itself was only intended to be used directly by Node2D, and thus only accounted for its behavior. If it was only artificial we wouldn't have it, and we wouldn't need a warning because it would just work as expected in every situation. |
This PR moves the
z_index
,z_as_relative
andy_sort_enabled
properties fromNode2D
toCanvasItem
.This could be quite handy for advanced UIs since it allows changing the drawing order of
Control
nodes.Closes godotengine/godot-proposals#839.
IMO this is a better place for the properties as the setters call
RS::canvas_item_set_z_index(...)
,RS::canvas_item_set_z_as_relative_to_parent(...)
andRS::canvas_item_set_sort_children_by_y(...)
internally which shows that the RS API is designed to work with CanvasItem, not just Node2D.Update: To prevent confusion a configuration warning is shown when changing the z_index of a
Control
node: