I use a structure to separate all body parts for their animation in AnimationPlayer, there are separate legs, arms, body, neck, head, etc., but I encounter a problem that some body parts overlap other objects, outside the character node, I use Y Sort, and CanvasGroup, and expected that all sprites will have one Z index, and if some object overlaps the character, then it will be overlapped entirely, not partially, what can help me? Do I really have to output all this to a separate Viewport? Which is not very convenient.
The issue @jeksun2022 is facing is that it’s not trivial in Godot to compose a character with many sprites of different Z index (to control the ordering of every body part regardless of their position Y), and then, draw the full character once, as one entity, so that all of its sprites are considered on the same order when it comes to drawing the character inside a full environment.
In Unity, you would do that with a component called Sorting Group. And as the documentation says:
Adding a SortingGroup component to a GameObject will ensure that all Renderers within the GameObject’s descendants will be sorted and rendered together.
A common use case for having a SortingGroup is to create complex 2D characters that are made up of multiple SpriteRenderers. When several clones of such a character overlap, their individual body parts might not be sorted properly resulting in a visual glitch where the the body parts interleave. For example, the hands of two characters might be sorted in front of their bodies, where you would expect one entire character to be drawn in front of the other character. The SortingGroup component solves this by ensuring the entire branch of the character are sorted and rendered together.
All this to say that, I don’t know any easy solution in Godot, I believe that doing some dark magic with another viewport is the way to go, but I wanted to give more info and the Unity’s equivalent, in case that would help someone come up with a better solution!
Yes, until yesterday I thought that CanvasGroup together with Y-Sort would work similarly to SortingGroup from Unity, unfortunately this is not the case.