godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Add Sorting Group functionality for CanvasItem sorting #9428

Open xmxy-wt opened 5 months ago

xmxy-wt commented 5 months ago

Describe the project you are working on

I am working on a sample project where each unit is assembled from various body parts, and different z-indexes are set for each body part to achieve a simple layering effect.

Describe the problem or limitation you are having in your project

However, when two units overlap on the map, a very bad phenomenon occurs. part_intersect

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The "Sorting Group" feature allows a parent node to treat all child nodes as a single sorting layer during sorting. This is crucial for animated characters composed of multiple body parts, as relying solely on Z_index for sorting when characters overlap can lead to poor results. For more details on this specific feature, please refer to this link: https://docs.unity.cn/2019.4/Documentation/Manual/class-SortingGroup.html.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

one unit character_hierarchy

two units overlapping part_intersect

The correct effect

unique_orderlayer

If this enhancement will not be used often, can it be worked around with a few lines of script?

You can control the layering of nodes using code to achieve the layering effect, eliminating the need for z-index. However, if the unit is composed of four directions, it will be very troublesome to modify the unit direction without using z-index, and the workload will increase several times.

Is there a reason why this should be core and not an add-on in the asset library?

I believe this is a essential feature for a game engine.

AThousandShips commented 5 months ago

Have you tried using canvas layers? And y-sorting?

xmxy-wt commented 5 months ago

Have you tried using canvas layers? And y-sorting?

Using "canvas layers" as the parent node allows for a layered display effect. However, the position of "canvas layers" cannot be modified; only the positions of its child nodes can be changed. This makes it very difficult to control characters, and the performance during testing is very poor.

xmxy-wt commented 5 months ago

您是否尝试过使用画布图层?还有 y 排序?

Using Y-ordering would completely eliminate the use of Z-index. In complex skeletal animation, it is difficult to give up on Z-index.

AThousandShips commented 5 months ago

Have you tried using relative z-indices? And putting each character on a z-index themselves?

xmxy-wt commented 5 months ago

您是否尝试过使用相对 z 指数?并把每个字符放在 z 索引上? If Z_index is set, Godot completely overrides the Y sorting and layer limitations, causing all characters under the same canvas to follow Z_index sorting. This would be very bad. ![Uploading part_intersect.png…]()

AThousandShips commented 5 months ago

You didn't upload the image

xmxy-wt commented 5 months ago

You didn't upload the image

Sorry, it seems there is a problem with the network. Can you please check the second image where I asked the question?

I'm really sorry. I'm worried that my use of translation software may result in unclear language expression and cause inconvenience for you.

AThousandShips commented 5 months ago

You can upload it again, you have to wait until it says done :)

Calinou commented 5 months ago

You may want to look into the CanvasGroup node as well.

dalexeev commented 5 months ago

Related:

AdriaandeJongh commented 4 months ago

Just to double check: if the parent of the unit / character in the original post's example has y-sorting enabled, but the unit root itself has it disabled, shouldn't that group the unit at its patent y-position regardless of the unit's subsequent structure?

xmxy-wt commented 4 months ago

In order to implement features like Ysort group, I spent a lot of work on animation. And the final product's performance fell short of expectations. I find it hard to imagine such a mature GODOT engine without such a feature.

Just to double check: if the parent of the unit / character in the original post's example has y-sorting enabled, but the unit root itself has it disabled, shouldn't that group the unit at its patent y-position regardless of the unit's subsequent structure?