قالب وردپرس قالب وردپرس قالب فروشگاهی وردپرس وردپرس آموزش وردپرس

Unity Z-Fighting Bug: Causes of Flickering Geometry and Reliable Solutions

Unity Animator State Machine Bug: Transitions Getting Stuck (Causes and Fixes)
Unity Animator State Machine Bug: Transitions Getting Stuck (Causes and Fixes)
February 15, 2026
Unity Sprite Atlas Padding Bug: Visible Gaps Between Sprites
February 15, 2026

Unity Z-Fighting Bug: Causes of Flickering Geometry and Reliable Solutions

Unity Z-Fighting Bug: Causes of Flickering Geometry and Reliable Solutions

You move the camera and two surfaces start flickering. The texture looks like it is vibrating. Sometimes parts of a wall disappear and reappear rapidly.

This is called Z-fighting. It happens when two surfaces compete for the same depth position in the rendering pipeline. Unity is not broken. The GPU simply cannot decide which surface should be drawn first.

Below is a structured way to understand and fix Z-fighting in Unity.

What Is Z-Fighting?

Unity uses a depth buffer (Z-buffer) to determine which objects are in front of others. Each pixel stores a depth value.

If two surfaces are extremely close together, their depth values become nearly identical. The GPU alternates between them each frame, causing visible flickering.

Step 1: Check for Overlapping Geometry

The most common cause is two meshes occupying the same space.

Examples:

  • Two planes placed at the same Y position
  • Duplicate walls stacked together
  • Decals placed directly on top of surfaces

Solution:

  • Slightly offset one mesh (for example, move it by 0.001 on one axis)
  • Remove duplicate geometry

Step 2: Adjust Camera Near and Far Clip Planes

The camera’s depth precision is not evenly distributed. A very large distance between near and far clip planes reduces depth accuracy.

Select your Camera and check:

  • Near Clip Plane
  • Far Clip Plane

Common mistake:

  • Near = 0.01
  • Far = 10000

This setup destroys depth precision.

Better example:

  • Near = 0.3
  • Far = 500 or lower if possible

The smaller the range, the better the precision.

Step 3: Check Large World Coordinates

If your objects are very far from world origin (for example, position 100000, 0, 100000), floating-point precision decreases.

This can cause visible Z-fighting even when meshes are not perfectly overlapping.

Solution:

  • Keep gameplay near world origin (0,0,0)
  • Use floating origin techniques for large worlds

Step 4: Use Shader Offset for Decals

If you intentionally place one surface on top of another (like bullet marks or road lines), offset the depth slightly using shader settings.

In custom shaders you can use:

Offset -1, -1

This tells the GPU to bias depth calculation and avoid conflict.

Step 5: Avoid Coplanar Surfaces

Coplanar means two surfaces share the exact same plane.

Example problem:

  • Floor mesh
  • Second decorative floor mesh exactly aligned

Instead, modify the mesh so they are not perfectly overlapping.

Step 6: Check Shadow Bias (Sometimes Looks Similar)

Sometimes flickering looks like Z-fighting but is actually shadow acne.

Select your Light and adjust:

  • Bias
  • Normal Bias

If adjusting bias fixes the issue, the problem was shadow precision, not geometry overlap.

Step 7: Use Higher Depth Precision (URP / HDRP)

If using URP or HDRP, check your rendering settings:

  • Depth texture precision
  • Renderer settings

Higher precision buffers can reduce artifacts in complex scenes.

Step 8: Avoid Extremely Thin Geometry

Very thin meshes (like 0.0001 units thick) can produce depth artifacts.

Increase thickness slightly if possible.

Quick Debug Checklist

  • Remove duplicate meshes
  • Offset overlapping surfaces slightly
  • Increase near clip plane
  • Reduce far clip plane
  • Keep objects near world origin
  • Adjust shader depth offset

When Z-Fighting Becomes Noticeable

Z-fighting is more visible when:

  • Camera moves slowly
  • Viewing angle is shallow
  • Surfaces are large and flat

Understanding when it appears helps you design around it.

Is This a Unity Bug?

No. Z-fighting is a fundamental limitation of depth buffers in real-time rendering. Every 3D engine can experience it.

The solution is always structural: improve depth precision or remove overlapping geometry.

Final Thoughts

Z-fighting happens when two surfaces compete for the same depth value. The GPU cannot consistently decide which one is in front.

Most cases are solved by adjusting clip planes or removing overlapping meshes.

Once you understand how the depth buffer works, flickering geometry becomes easy to diagnose and prevent.

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar