Quick answer: Within a layer, order is mostly arbitrary. Use layer_depth(layer, depth) or move elements to different layers (different depths) for explicit ordering.

A top-down ARPG wants the player above shadows but below the UI. layer_element_move places elements onto a layer but doesn’t establish per-element z within that layer.

Use Layer Depth

Each layer has a depth value. Lower depth = drawn later (in front). Common:

layer_create(-200, "FrontFX");
layer_create(-100, "UI");
layer_create(0, "Entities");
layer_create(100, "Shadows");

Tune depths per design intent.

Y-Sort for Top-Down

For top-down where nearer entities should draw above farther ones, sort by Y per frame:

// Step event of each entity
depth = -y;

GameMaker treats depth as Z; lower = front. -y sorts by screen Y; higher Y = more front. Smoother than layer reshuffles.

Per-Instance vs Layer

Setting instance.depth overrides the layer’s assignment. Use for fine ordering within a logical layer.

Verifying

Order correct visually: shadows behind player, UI on top. As player walks past trees, sprite occludes / is occluded by trees naturally.

“GameMaker draws by depth, not arrival order. Layers are buckets with depth values.”

For per-pixel front/back ordering between two entities, use sub-layers or fine-grained depth=-y — clean and predictable.