Textures are being displayed in the wrong order - How can I fix this?

Hello, we are currently working on a 2D Platformer. The Objects in the game are represented as textures on a plane with invisible bounding meshes as platforms.

We use the normal perspective camera instead of the orthographic one so we can have background objects at different z-coordinates to simulate parallax scrolling.

However there seems to be a problem with this method. In the inspector, in the game and also in the build game some objects are shown as being in front of other objects even though they are technically behind them.

Example:

6336-mushroomwrong.png

The mushroom is actually 5 units behind the tree but still shown in front of it. If I move the character however:

6337-mushroomright.png

If I’m above the mushroom it is shown correctly. Even if I place the mushroom about 20 units behind the tree it is still shown to be in front of the tree, it only gets smaller. This problem doesn’t exist in orthographic projection but we would loose the parallax scrolling if we were to use that. I don’t know what’s causing the problem or how to fix it. Anyone got an idea?

It is usually quite hard for an engine to get the correct render order with transparent materials, especially Alpha Blended materials. Alpha Tested materials don’t have this problem AFAIK. Try a cutout shader. If that doesn’t work, you can also change the render order per script.