Problem with roads breaking when playing delivery driver game

Hi all, I am having an issue where the roads on my game layout ‘break’ apart when I play the game, but they all look connected in the scene view. See below:

Not a big deal to me as this is just a practice game, but I am curious to know what would cause this behavior?

The only thought I had was to change the order layer of the roads from 0 to 1, but the issue persisted.

Any other ideas?

Hi,

Welcome to our community! :slight_smile:

That looks indeed odd.

First of all, move the camera back a bit meaning set its position to z = -10. If it shares the same position as the roads, it might be that the roads partially disappear. Just like we cannot see anything that’s on or in our eyeballs. That’s a typical problem in Unity.

Another typical problem is overlapping sprites sharing the same z-position. If adjusting the camera position did not fix the problem, I suspect that you are experiencing the infamous z-fighting effect. When two sprites share the same z-position, the renderer does not know which one to render first, and it renders the sprites in a random order.

The solution is the same as with the camera. In this case, you would set the z-position of a sprite that is supposed to behind another one to z = 1 (if the sprite in front of it is at z = 0).

Alternatively, you could use the Render In Order in the SpriteRenderer component to define the render order of your sprites.

Did this help you fix the issue?


See also:

Perfect – it looks like the issue was the z-fighting effect you described in the second paragraph. Some roads overlapped so I changed the z on those to 1 and it completely resolved the issue.

Thanks for the troubleshooting Nina, and the explanation behind why this was happening.

Fantastic! :slight_smile:

The z-fighting effect is very common in computer graphics in general, not just in Unity. It’s a good thing that you experienced and fixed it so early. If you see a similar issue in your future games, you’ll know what to check first.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms