In this tutorial I will go over the simplest way to make a Z sorting system. This system is very simple to write and to understand.
The idea
On every frame, we want to reorder every object so they draw from top to bottom. Therefore the z order will depend on the Y coordinate of the object.
How to do that
Create a family that will contain every object that will get ordered. Let’s name it ZOrder.
Once that is done, this is what we want to do:
However, this is not the best way to do it. Here we do a for each loop on every tick, which can prove to be very slow when dealing with lots of objects. Instead we can add an instance variable to the ZOrder family, and name it “order”. Once that is done we can use the premade system action for reordering objects.
That's it. For the simplest z order system, all you need are these 2 actions.