Unified Bed Leveling (UBL): The Ultimate Guide

Justin Cuellar By Justin Cuellar, Senior Engineer
Published: December 30, 2019
A digital 3D visualization of a printer bed mesh topology with a nozzle hovering above it.

If you’ve been 3D printing for more than a week, you know the lie: "Just level your bed."

The truth is, even if you perform a perfect four-corner manual level, your build plate isn't perfectly flat. It’s likely a microscopic mountain range of dips and bows. Aluminum warps when heated, and glass isn't as flat as it looks. This topology causes those frustrating first-layer inconsistencies where one side of the print is perfect, and the other is scraping the glass.

Enter Unified Bed Leveling (UBL).

If standard auto-leveling is a map, UBL is a 3D topographic survey. It is arguably the most advanced leveling system available in Marlin firmware today, combining the precision of a mesh with the ability to edit, save, and tilt that data to ensure your nozzle stays perfectly equidistant from the bed across every millimeter of travel.

Let's get your printer updated and your first layers flawless.

Why UBL? (The Bed Leveling Landscape)

Before we start compiling firmware, it helps to understand why we are choosing UBL over the other options. Most printers ship with basic leveling enabled, but upgrading to UBL unlocks features like mesh editing and multiple save slots.

Method How it Works Pros/Cons
3-Point Leveling Probes 3 points to define a plane. Fast, but assumes the bed is perfectly flat (it rarely is).
Linear Leveling Probes a grid and tilts the plane. Better than 3-point, but still ignores localized warps.
Bilinear Leveling Probes a grid and creates a mesh. Standard for most ABL. Good, but lacks editing tools.
Unified Bed Leveling (UBL) High-res mesh + Editing + Save Slots. The Gold Standard. Allows fine-tuning and saving multiple meshes.
Before You Start

UBL is an advanced feature. Ensure you have the following ready before proceeding:

  • A Working ABL Probe: We highly recommend our 3DM Touch. Inductive probes work too, but contact probes are preferred.
  • A Manually Leveled Bed: ABL compensates for warping, not a crooked bed. Tram your four corners first!
  • Firmware Tools: You need VS Code (with PlatformIO) or Arduino IDE to edit and flash your printer's firmware.

Step 1: Enabling UBL in Firmware

To utilize UBL, you must enable it in your Configuration.h file in Marlin. This tells the printer to allocate memory for the mesh data.

Open your firmware project and search for the Bed Leveling section. You need to comment out (add //) the other methods and uncomment (remove //) UBL.

In Configuration.h:

//#define AUTO_BED_LEVELING_3POINT
//#define AUTO_BED_LEVELING_LINEAR
//#define AUTO_BED_LEVELING_BILINEAR
#define AUTO_BED_LEVELING_UBL  // <--- Uncomment this line
//#define MESH_BED_LEVELING

Next, ensure the leveling state is restored after homing. By default, the G28 (Home) command turns off leveling. We want it to turn back on automatically.

#define RESTORE_LEVELING_AFTER_G28

Configuring The "Fade Height"

Fade height is a powerful feature often overlooked. It tells the printer: "Correct for the uneven bed on the first layer, but gradually stop correcting as the print gets taller." By the time the print reaches 10mm high, the layers are perfectly flat, and the Z-axis motors stop constantly moving up and down.

Image showing a diagram of 3D Printing Fade Height explanation.

Ensure these lines are uncommented:

#if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL)
  #define ENABLE_LEVELING_FADE_HEIGHT
  #define G26_MESH_VALIDATION 
#endif

Also, set your grid points. A 10x10 grid offers excellent resolution for standard beds (Ender 3 size), though it takes longer to probe.

#define GRID_MAX_POINTS_X 10 
#define GRID_MAX_POINTS_Y GRID_MAX_POINTS_X

Once these changes are made, compile the firmware and flash it to your mainboard.

Step 2: The Perfect UBL Start G-Code

Now that the firmware understands UBL, we need to tell the slicer how to use it. This is done in your Start G-Code settings in Cura, PrusaSlicer, or OrcaSlicer.

Here is the robust "Generate and Print" sequence. This sequence creates a fresh mesh for every single print.

M190 S{material_bed_temperature} ; Wait for bed to reach temp
G28      ; Home XYZ
G29 P1   ; Automated Probing (The main scan)
G29 P3   ; Smart Fill (Extrapolate unreachable areas)
G29 F10  ; Set Fade Height to 10mm
G29 S1   ; Save this mesh to Slot 1
G29 A    ; Activate UBL System
G29 L1   ; Load the mesh from Slot 1
M500     ; Save to EEPROM

Understanding the Commands

It can be scary to paste code you don't understand. Let's break down exactly what the machine is doing.

M190 S{...}: This is critical. We heat the bed before probing. Materials expand when hot; probing a cold bed will give you an inaccurate mesh for a hot print.

G29 P1: The heavy lifting. This commands the probe to check all reachable points defined in your grid (e.g., the 10x10 grid we set earlier).

G29 P3: This is the "Smart Fill." Your probe likely cannot reach the absolute edge of the bed because of the offset distance from the nozzle. P3 tells the printer: "Take the data you DO have, and mathematically guess the height of the areas you couldn't reach." Without this, the printer assumes unprobed areas are at "0", which can crash the nozzle.

Diagram showing places the ABL probe can reach in green vs the places it can't reach in red.

G29 F10: This sets the Fade Height to 10mm.

Why Use Fade Height?
If your bed is tilted, and you don't use Fade Height, your entire print will be slightly tilted (like the Leaning Tower of Pisa) because the Z-axis preserves that tilt forever. Fade Height gradually removes that compensation so the top of your print is perfectly square to the frame, not the bed.

Advanced UBL Workflow: The "Save & Tilt" Method

The method above (probing every single print) is accurate, but slow. A 10x10 grid is 100 probe points! That takes time.

Because UBL allows you to save meshes, you can actually probe the bed once, save it, and then just check the tilt before each print.

1. Create the Master Mesh (Do this once via terminal):
Run G28, then G29 P1, then G29 S1. This saves a high-res map of your bed's imperfections (high and low points) into Slot 1.

2. The Fast Start G-Code (Put this in your Slicer):
Use this code for your daily printing. It loads the saved mesh and just does a quick 3-point check to see if the bed angle has changed.

M190 S{material_bed_temperature}
G28      ; Home
G29 L1   ; Load the Master Mesh from Slot 1
G29 J    ; "Tilt" the mesh
G29 F10  ; Set Fade Height

G29 J is the magic command here. It probes just 3 points to calculate the plane of the bed, then takes your saved high-res mesh (loaded with L1) and tilts it to match the current bed position. This gives you the accuracy of a 100-point probe with the speed of a 3-point probe.

Save Your Settings!
After running a full system scan (G29 P1), you MUST run M500 to save the data to the printer's EEPROM. If you turn off the printer without running M500, that beautiful mesh you just created is gone forever.

Summary

Unified Bed Leveling is intimidating at first glance because of the "Configuration.h" work, but the payoff is massive. You get a first layer that sticks perfectly edge-to-edge, and if you use the "Load and Tilt" method, you don't even lose time waiting for probing before every print.

Key Takeaways
  • Heat first: Always heat your bed to printing temps (M190) before running UBL commands.
  • Fill the gaps: Always use G29 P3 after probing to fill in data for the edges of the bed the probe can't reach.
  • Fade it out: Use G29 F10 to fade out correction over the first 10mm for dimensionally accurate parts.
  • Save it: Use M500 to save your mesh to the printer's memory.
FAQ
Do I need to re-probe if I change my nozzle?

Generally, no. Changing the nozzle affects the Z-offset (distance from nozzle to probe trigger point), but it doesn't change the shape of the bed. You should re-calibrate your Z-Offset, but your UBL mesh topology should remain valid.

Why does the nozzle move up and down during the first layer?

This is UBL working! The Z-axis motors are actively moving the nozzle up and down in real-time to follow the contours of your warped bed. This ensures the plastic is squished onto the plate with consistent pressure everywhere.

What is the difference between G29 P1 and G29 P3?

G29 P1 performs the actual physical probing sequence. G29 P3 is a mathematical function that runs afterward to fill in the "holes" in the data map where the probe physically couldn't reach.

Back to blog

3 comments

I just have to say that I really appreciate the graphic you have for explaining fade height. I remember having an awful time trying to figure out what it meant when I installed a bltoutch on my machine. After rereading explanations of fade height many time I eventually got a picture in my head that is exactly like that graphic. Would have been so much easier if I had found this article

Mendel

Can you just use the gcode in you slicer without changing the firmware?

IDM

Can you just use the gcode in you slicer without changing the firmware?

IDM

Leave a comment

Please note, comments need to be approved before they are published.