Ysort is not working with an instanced scene of many objects

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Idleman

I want to have a set of about 10 different rocks in my world environment. I have added 10 sprites with texture of different rocks and attach a Static Body + CollisonShape2D to each one of the sprites.

If I put the 10 sprites as nodes directly with the player node inside a Ysort under the world scene, the Y sorting works, and my player could go behind the rocks. However, if I put the 10 rocks in a separated scene (a rock scene), and instance the rock scene with the player node to the world, The Ysort does not work anymore, the player could only go behind one rock not all rocks.

I think that is because the world scene only use 1 Y coordinate from the Rock scene. My question is that, is there any setting I have to turn on to allow Godot uses all the Ysort coordinates for different CollisonShapes from an instance scenes? Thank you.

:bust_in_silhouette: Reply From: Idleman

Found a solution to my problem. I put a few objects under Node2D as a scene, and when I instanced that scene to the world scene, Ysort is not working. As I have changed the Node2D to a Ysort node, and it works. Now all objects in the instanced scene works nicely with Ysort in the world scene.

Thanks for following up, this helped me a couple of years later! I had a common enemy scene under base KinematicBody2D and was instancing that scene inside other scenes for the specific enemy types, under a base Node2D (i.e. my Enemy KinematicBody2D scene was placed as the first child of the Vampire Bat Node2D scene, hope that makes more sense). The Node2D position was not tracking, but the child KinematicBody2D was. Changed the Node2D to a Ysort, works fine now. Hopefully it doesn’t cause other issues later, don’t know why it would though.

PIZZA_ALERT | 2022-05-09 04:15