2D sorting order render issue

Hi there,

I’m a noobie who is trying to make my first 2d top down game with Unity. I’ve been following this tutorial to emulate the 3d effect using the sorting order. I’ve follow this tutorial almost to the T.

Like in the video I put my player sprite under an empty object to offset the pivot, and put a sorting group component on it. Like in the video, when I moved the whole Parent object around a wall in Scene, it works as intend (with the character appeared behind the wall when I move up the Y-axis.)

However, the problem happen when I test in out in the game. And instead of popping up and behind according to the character movement around the wall. It seems like the sorting order remains in relative to where the character spawn and stay that way. So if I start the game with the character under the wall, he will forever be above the wall (and if I start it with him above the wall, then he will forever remain behind that wall.)

But if I took the character sprite out of the parent empty option (without the sorting group component), then it works as intend (but the pivot will stay in the middle, and I will have to change every single frame of my sprite animation.)

Am I missing something? In his video it seems to work perfectly yet mine just doesn’t want to cooperate. :(:(:frowning:

Hard to say, but sounds a bit like your movement script may be altering the local position of the visual, and not the position of the sorting element. Check to see if that is the case while running, just check the transform of your sorting element and see if it is moving or staying still. If that is the cause, they you just need to change how your movement script works so that it alters the correct object’s position.

1 Like

Thank you for replying.

How do we check that? When I run, I see that the sotrting order number doesn’t change at all in the inspector tab (but this is the case for either when it’s working fine by itself or under the parent with the sorting group componenet.)

Btw here’s my movement script. :face_with_spiral_eyes::face_with_spiral_eyes:

Select either the parent or child object in your hierarchy while running the game. You can then inspect their transform values. The parent (the one determining sorting) should have its position move, while the child should have its position remain static and unmoving (relative to its parent). If that is not what is happening, you have to alter how your movement script works as it is altering the incorrect object’s transform.

You don’t really care about sorting order here as unity is determining that itself via the Y component of the position.