Performance hit by Z-fighting in my 2D game

Hi, this is a question mainly about 2D development, but a 3D guru may still be able to answer it … hopefully!

I am developing a 2D space shooter. My camera is orthographic and I am using 2D sprites. Everything is fine in terms of movement and collision. I tend to run my game at 240FPS just to see if any level has a performance hit.

On my 3rd level, the FPS drops a fair bit simply because my space invader enemies on this level are generally overlapping each other as they move. I only have 26 of them and they are all rendered on the same Z position.

My spaceship and spaceship laser are also on the same Z position. This enables the laser (and space invader) to generate overlap events when they collide.

If I render the 26 enemies with a Z position of 1 pixel apart, then there is no slowdown! But I can’t do this as my spaceship laser needs to collide with the enemy on the same Z position!

I’m guessing the slowdown is due to Z-fighting.

I don’t really know a way around this.

Any help would be appreciated.


The answer is likely draw calls, NOT z-fighting, unless you see flickers when enemies overlap, easy fix in that case, add a random offset distance between -1 and 1 units, Draw calls are increased by having many actors/materials onscreen. Also, im assuming your collision is paper thin boxes, in that case make them a bit thicker to compensate. If your using tick to see if the laser is colliding with an enemy, your doing it wrong, switch to normal collision, your frames will thank you.

Also, if your game is literally slowing down at lower framerate, not moving at a constant rate but more stutter-y, multiply your movement values by delta time, and reduce them to like 2%, and tweak from there. Its a night and day stability increase.

Delta time is also why bethesda games are clamped to 60fps, because they for some reason won’t use a patch that has existed for over 23 years. They clearly cant multiply either by delta time or by detail (“16 times the detail” Fallout 76 -- Bugs Compilation - YouTube)

Thank you so much Bits360!

You said:

> Also, im assuming your collision is paper thin boxes, in that case make them a bit thicker to compensate.

You hit the nail on the head! I’ve set each alternate enemy on a Z-level +/- 2 units and set the collision thickness of my laser to 3.0! Bam! It works, and I get my performance!

Yes, I am using normal UE4 built-in collision.