in 2D the option z as relative doesnt do anything ?
All of a sudden this solution shows up has a way to fix things on a google search.
If i have a character made of 15 bodyParts, where the left arm and left leg need to be behind the others parts, by using z index -12 this part will show up behind the background, even if the z index of the parent is 0.
The only way is to change the nodes order in the tree which is a total mess, ( garbage hidden under the carpet )
Why is z index has relative working like this or even there ? it doesnt make sense…
z-index is a per-layer value not per-node. Nodes are drawn in tree order so moving them as needed is the correct solution. You can also use CanvasItem.show_behind_parent in some cases.
What do you mean? How are you updating their position in the tree? How is using a viewport a solution? Are you sure you can’t re-work the scene nodes re-parenting them as needed and using show_behind_parent instead?
z as relative adds the parent ‘effective’ z index to its own index. By effective, it means the final z index considering the z as relative option and parent nodes…
If your parent z index is 0 and node z index is -12, then the effective z index of the node is -12. And I assume your ‘background’ z index is also 0. Since 0 is bigger than -12, background is drawn on top of the node.
You need to set your characters main node z index high like 50 (this is just a suggested number based on very limited information about your game)
subViewPortContainer/subViewPort, Is the only way to go, or you will have to change your levels front/back background’S to very high values like 1000, -1000. And im using viewport texture on a sprite2d to apply the shaders.
Plus are you sure that when 2 characters, meet their legs/arms/torso, wont intertwine with each other ?
If you need subviewport for your shader, then it’s ok to have it.
But if you only add the subviewport because of the z_index issue, then it’s probably overkill. It may also cause performance issues if you have a lot of ‘characters’ that requires their own subviewport.
Why that high? You have around 15 body parts. That’s why I said make 50 as your character main node z_index. Then you can add relative z_indexes on the body parts, and change them if needed. But they should not be changed all the time.
When z_indexes are same, drawing order is determined by scene tree order or (if enabled) y sorting. So they won’t interwine.
Also don’t get me wrong, if your current solution with viewport works, it’s also fine. There is no one solution to the same problem. But again, it may not be the optimum solution for your game.
But I must say your sentence below is very wrong. It works pretty good. I think you just don’t know how it works or how to use it properly. You need to research a bit more on the subjects of z_index, y_sorting, z as relative, how godot 2D drawing order works etc…
If you tried and it works !!! I didnt knew it worked because i never tried.
I never tried crossing 2 characters to see if their body parts cross each other, instead of showing one character passing in front and other passing in the back.
subviewport because of the z_index issue, then it’s probably overkill.
its the only thing avaiable… An outline shader its going to be a problem he applies the shader to each body part instead of the entire character…
Canvas group with the z index out of Zero doesnt work…
Have you tried the new DrawableTexture2D ?
Or using the rendering server…
subViewPort so far hasnt caused me any performance problems… I dont know im just turning the visibility subViewPort to OFF, then the sprite2D subViewPort Texture on Top with visibility ON, but maybe godot draws 2 chacters instead of 1 i dont know !
Subviewport is the only thing avaiable… that works 100%
Of course it looks scary, it takes subviewportContainer/SubviewPort, and there is a bunch of things in there, overwrite, XR, Input, MSAA, TAA, Filter, Texture… sht all over the place… cr4p that doesnt do anthing… Or if it doesnt something, i dont know… Is it used in a game for killing zoomies ? Makes the Boss turn Green ? Makes the Sun ray more round ? Nobody knows this sht, because the game that was using that, was never finished… Problably the person who coded it decided to put all those vars in there, so it didnt want to waste time coding them on script…
Theres other stuff "DrawableTexture2D " what is this stuff being used in ? The same has surface create in GM, to stack a bunch of textures / shaders and then draw a texture ? To group draw a bunch of pinguins togheter ? An apocalipse Game, to make the enviorement night and day ?
A guy on youtube does a video about this stuff, and its all very cute, very lovely…etc… But then he doesnt know nothing about it, skips and moves to the next thing…
Now if you have characters 500 sprites animations, at 630FPS, you use a subviewPort on each character, maybe the performance drops to 590FPS, but with bones and skeletons the performance problem is diferent, the CPU is calculating those positions… the performance problem never reaches the subViewport, before this skeleton things drops the FPS to 20