Paper2D Sprite Sorting?

Hello there,

currently I am trying to learn how to do 2d games using UE4 and having some trouble with how the sprites get rendered.
I am interested in making a 2d RPG using the experimental tilemaps for learning purposes. When I try to add an object
to the tilemap that “stands” on it (e.g. tree), the character either is always rendered in front of it or behind it, but the
expected behaviour would be a rendering order based on the z-coordinate of the bottom-center pivot of the rendered sprites
so when the character actually stands in front of it, the character is rendered in front and vice versa.
What I have tried so far is using the TranslucentUnlit Material to disable the depth test, experimenting with the corresponding
axis setting in the project settings but none of them seem to work.
It would be nice if someone could point me in the right direction, thanks a lot!

Hello and welcome to Unreal!

I have personally answered this question many times so it amazes me that you weren’t able to find what you are looking for.

In any case there are 2 ways that you can sort z translucent order. Go to the project settings under rendering and either choose based on actual depth (pixels) or you can ignore depth and opt for sort translucency order. If you choose the second option click on the actor, go to details panel and in the search bar type sort. It is zero based meaning that 0 is furthest back and as you add 1 you come closer to the foreground.


Hi, thanks for your answer!

The translucency order does not work in this case because all it does it layering the sprites based on the chosen value for each sprite. In 2d rpgs there is a “in front of” and “behind” an object.
If my character stands right in front of a tree, I want the character to be drawn on top of the tree. If he stands behind the trunk, I want the tree to be rendered in front. This is partly doable by
configuring the axis which is used to calculate translucency order (using z axis with a value of 1.0). Problem here is, the z-value for sorting purposes is determined using the center of the sprite, but I
need it to use the bottom value of the sprite (where I set my pivot point). The effect is that my character is in front of the object for the first half of the sprite and behind it for the other half, which is
only working for very small objects, but not for trees for example.
So what would actually help me is a way to change the point it uses to sort the sprites along my chosen axis and I haven’t found one for now. What I understand is that your proposed solution works fine
for 2d plattformers.

Kind regards

Hey there, I solved this problem, but you’re not going to like the solution. Essentially, you are going to make a parent actor with a sprite object, you are then going to get a reference to your character. You are going to add one if on one side of the origin, take away one in the sort order if you are on the other side. It is messy, and requires you to keep careful track of your character sprite sort order.

I found the best way to handle this, is to make a series of parent actors with sprite components, and then make my own sorting variable, where it will automatically handle assigning the sorting on start. In this way, I can have dynamic sorting.

Edit: You are also going to make sure there is a collider preventing the character from bypassing the sort point on the origin, or you will see the character ‘walking through’ it. You could also make a Vector2 variable to store the sort point.

Thanks for your help, I will give it a try. Does anyone know if there are any planned changes that could help on that matter in the near future?

edit: found a simpler solution (except if I just misunderstood you): assign the negative z-location as translucent sort priority. This has to be updated each tick (or on each location change) for dynamic objects and once on BeginPlay for static objects.

Set in project settings translucent sort order to be by axis. This does not work for large tilemaps vs actors because the entire tilemap’s location as a whole, instead of individual tiles locations, is compared to the actor’s location to decide who is in front. But it works on a per actor basis.

Maybe you can try to use DefaultLitSprite Mateiral instead of TranslucentUnlit Mateiral nor DefaultSprite Material.