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.

Cheers!

2 Likes

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

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.

Hey there! First thing to know is translucency order will only work when your material will use translucent material.
ex. TranslucentUnlitSpriteMaterial, TranslucentLitSpriteMaterial, (already comes with paper2D plugins)


Suppose you have 2 sprites in same position. If you want to sort their order
You need to

  1. Set their material to TranslucentUnlitSpriteMaterial(light won’t affect) or TranslucentLitSpriteMaterial (Light will affect). Using other material rather than translucent, sorting order won’t affect anything)

  2. Now under sprite rendering section in details panel. set their sorting priority. ex. lets say, sprite 1 will be behind. So it will be 0 and sprite 2 will be front of that. so, it’s sorting order will be 1.

This is the correct way of sorting. if you sort sprite by moving their depth position in transform it will be a very bad idea and you will face a lot of issues while interacting with each other.

2 Likes