Quick answer: Set the TileMap's y_sort_enabled per-layer (not just on the node) and ensure y_sort_origin matches your art's pivot.

If you are searching for how to fix godot tilemap y-sort not respecting z-index, you are in the right place. This is a recurring issue in Godot that catches both new and experienced developers. The behavior looks like a deep engine bug, but the root cause is usually a small interaction between two systems that the documentation does not call out. Below is the full breakdown of the symptom, why it happens, a step-by-step fix you can apply today, and the diagnostic workflow to confirm everything is working.

The Symptom

Your top-down game has a TileMap with trees and a player character. You enable Y Sort on the TileMap, but the player still renders consistently above or below trees regardless of their relative y positions. The expected depth ordering doesn't take effect.

This kind of symptom tends to be deterministic in the editor but harder to reproduce in shipped builds, where the conditions that trigger it depend on player behavior, hardware, or timing that you cannot fully control during development. If you have a player bug report that matches the description above, the same fix usually applies.

Root Cause

Godot 4's TileMap exposes y_sort_enabled at two levels: the TileMap node itself, and each TileMap layer individually. Enabling only the node-level flag triggers sorting for the TileMap's own children, but the per-tile y-sort within a layer requires the layer's own flag. Layers default to disabled, so per-tile sorting silently does nothing.

This pattern shows up in many areas of Godot where two subsystems communicate through a shared but loosely-typed contract. The first subsystem reports success at its layer; the second subsystem silently rejects or transforms the data without an error. Because there is no exception at the boundary, the only visible evidence is the wrong output at the end of the pipeline, which is where most developers start their investigation. Tracing the bug backwards through the layers reveals the actual mismatch.

The Fix

Step 1. Select the TileMap node, expand the Layers section in the inspector, and enable Y Sort Enabled for each layer that should participate in depth ordering.

# Enable y-sort programmatically on all layers
func _ready():
    var tilemap = $TileMap
    tilemap.y_sort_enabled = true
    for layer_idx in tilemap.get_layers_count():
        tilemap.set_layer_y_sort_enabled(layer_idx, true)

Step 2. Set the y_sort_origin per tile in the TileSet editor. The origin defines the pixel within the tile that represents its 'feet' - the y value used for sorting. For trees, set origin to the bottom of the trunk.

# Per-tile y_sort_origin (TileSet editor)
# Open TileSet → Select tile → Rendering → Y Sort Origin
# Tree: set origin to (0, 16) for a 32x48 tree where the base is at y=48

Step 3. If sprites sort wrong despite correct settings, check that the parent Node2D's y_sort_enabled is also true - sorting is hierarchical and must be enabled at every level up to the root container.

Diagnostic workflow

Before you call the bug fixed, walk through this short checklist to confirm the fix addresses the actual cause and not a similar-looking symptom. First, reproduce the issue deterministically in a minimal scene. If you cannot get the same failure twice in a row, your fix attempts will be hard to evaluate, so spend the time to lock down a clean repro before changing any code. Second, apply only the fix - resist the urge to also clean up surrounding code. A single-variable change makes it obvious which edit resolved the symptom. Third, run the repro three or more times after the fix to confirm the issue does not return intermittently.

If the fix works in the editor but the symptom returns in a build, the most common explanation is a configuration difference. Build settings, asset import flags, and platform-specific feature toggles can change behavior between editor playthrough and shipped binary. Add platform-conditional logging around the fix code, ship a debug build with the logs enabled, and verify the relevant configuration values match expectations on the target device.

Why this happens

This bug class lives at the boundary between two Godot subsystems. The first system reports success at its layer; the second system silently rejects or transforms the data without raising an error. Because the boundary is not loud about its expectations, the symptom only appears at the end of the pipeline. The fix above addresses the configuration mismatch at the boundary - once the two systems agree on the data contract, the symptom disappears immediately.

This is also why the bug feels disproportionate to the fix. A one-line change resolves what looked like a fundamental engine problem because the engine was working correctly all along - it was just being asked to do something slightly different from what the calling code expected. Understanding the boundary contract is the durable lesson; the specific fix is the immediate payoff.

Verifying the fix

Reproduce the original symptom in isolation before applying the fix. If you cannot reliably reproduce, you cannot reliably verify - and you risk shipping a fix that addresses a different bug. Start with a minimal scene or scenario that triggers the issue every time, apply the change above, and run the same scenario at least three times to confirm the symptom is gone. Once the minimal repro is clean, retest in the full game to confirm the fix doesn't regress anything else.

For shipping games, follow a staged rollout. Push the fix to five to ten percent of players first, monitor the affected metric (crash rate, error log frequency, gameplay telemetry) for twenty-four to forty-eight hours, and expand only if the data confirms the fix without regressions. A staged rollout is cheap insurance against an interaction you did not anticipate in your test environment.

Capturing the bug from players

The hardest part of fixing this kind of issue is getting a player report that includes enough context to reproduce. Most players describe the symptom in their own words and omit the build number, scene name, hardware, or input sequence that triggered it. Without those details, you are guessing at the conditions and that guesswork is where most engineering time is wasted on production bugs.

A bug reporting SDK like Bugnet for Godot captures the build SHA, scene name, recent logs, device specs, frame rate, and a screenshot automatically whenever a player files a report. With that bundle attached, you can reproduce the bug locally instead of guessing - typically the difference between a one-day fix and a one-week investigation. The same SDK also catches unhandled errors automatically, so you get the report even when the player does not file one.

Edge cases to watch for

The same root cause can produce slightly different symptoms in adjacent systems. After fixing the case you found, spend thirty minutes searching your project for similar patterns - the same API called with different arguments, the same data flow with a different entity type, or the same lifecycle issue in a sibling module. Each match is a candidate for the same fix, or a related fix that prevents future bugs of the same class. Building this catalog of 'we've seen this before' pattern is valuable institutional knowledge that compounds with each project.

Pay extra attention to boundary conditions - the first frame, the last frame, zero or maximum values, and the transition between two states. These are where engines often have undocumented behavior, and where regression tests pay the highest dividend. A test that exercises the boundary catches the subtle regressions that look like new bugs but are really the original returning. Add one or two of these boundary tests after every bug fix; they earn their keep over the long life of the project.

When to escalate

If you have applied the fix above and the symptom persists, the bug is likely in a different layer than this article addresses. Capture a video of the symptom, the exact reproduction steps, the Godot version, and any recent changes to the project. File a report on the official issue tracker with that bundle - the maintainers are responsive when the report is complete, and a well-reproduced issue often gets a workaround posted within a few days.

Before filing, search the existing issues for keywords related to your symptom. Many bug reports are duplicates of issues that have a workaround posted in the comments but no formal fix in the engine. Reading the existing thread often resolves the issue faster than a new report, and adding a +1 with your repro to an existing issue is more useful to the maintainers than another duplicate. For paid licenses (Unity Pro, Unreal Source Access), use the support portal for faster turnaround on engine-level bugs.

Check the boundary; the bug lives between systems.