# GUI line connected to a control linked to a mesh, with higher zIndex got clipped at random place

**URL:** <https://forum.babylonjs.com/t/gui-line-connected-to-a-control-linked-to-a-mesh-with-higher-zindex-got-clipped-at-random-place/61796>\
**Category:** Bugs\
**Tags:** gui\
**Created:** [December 15, 2025, 4:09am UTC](https://forum.babylonjs.com/t/gui-line-connected-to-a-control-linked-to-a-mesh-with-higher-zindex-got-clipped-at-random-place/61796 "2025-12-15T04:09:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwiglydee](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qwiglydee/32/52554_2.png) [@qwiglydee](https://forum.babylonjs.com/u/qwiglydee)\
**Post date:** [December 15, 2025, 4:09am UTC](https://forum.babylonjs.com/t/gui-line-connected-to-a-control-linked-to-a-mesh-with-higher-zindex-got-clipped-at-random-place/61796/1 "2025-12-15T04:09:13Z")

</div>

Hi.

The setup is simple:

- there’s a control linked to a mesh representing an anchor, with zIndex 2
- there’s a line connected to the control, it’s with zIndex 1, so that it’s below the anchor.

[https://playground.babylonjs.com/#5SVAQB#3](https://playground.babylonjs.com/#5SVAQB#3)

Initially it is drawn fine, but then mesh moves (by key ‘Space’ in the playground), everything get redrawn and the line got clipped at random places, somethimes it’s completely not rendered.

That happens with `Ellipse` and `Rectangle` as anchors.

That does not happen with my custom control `MyDot` or built-in `TextBlock`.  
But they both produce another bug with infinite relayout somehow.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [December 15, 2025, 4:12pm UTC](https://forum.babylonjs.com/t/gui-line-connected-to-a-control-linked-to-a-mesh-with-higher-zindex-got-clipped-at-random-place/61796/2 "2025-12-15T16:12:21Z")

</div>

cc @amoebachant 🙂

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [December 15, 2025, 4:12pm UTC](https://forum.babylonjs.com/t/gui-line-connected-to-a-control-linked-to-a-mesh-with-higher-zindex-got-clipped-at-random-place/61796/3 "2025-12-15T16:12:27Z")

</div>

Assigned @amoebachant on December 15, 2025, 4:12pm UTC



---

<div class="post-metadata">

**Author:** ![qwiglydee](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qwiglydee/32/52554_2.png) [@qwiglydee](https://forum.babylonjs.com/u/qwiglydee)\
**Post date:** [December 15, 2025, 5:14pm UTC](https://forum.babylonjs.com/t/gui-line-connected-to-a-control-linked-to-a-mesh-with-higher-zindex-got-clipped-at-random-place/61796/4 "2025-12-15T17:14:34Z")

</div>

Apparently, the line is clipped by a rectangle of its previous position.  
It’s quite testable by putting fingers on screen.

However, `gui.useInvalidateRectOptimization = false` does not help.  
There’s something else.

---

<div class="post-metadata">

**Author:** ![amoebachant](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/amoebachant/32/39450_2.png) [@amoebachant](https://forum.babylonjs.com/u/amoebachant)\
**Post date:** [December 16, 2025, 1:38am UTC](https://forum.babylonjs.com/t/gui-line-connected-to-a-control-linked-to-a-mesh-with-higher-zindex-got-clipped-at-random-place/61796/5 "2025-12-16T01:38:29Z")

</div>

Hi @qwiglydee - thanks for this bug report! I was able to track down the root cause today, and here’s the PR with the fix: [GUI: Fix Line layout bug when a connectedControl has a higher zIndex by AmoebaChant · Pull Request #17558 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/17558)

I appreciate you reporting this bug!

---

<div class="post-metadata">

**Author:** ![amoebachant](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/amoebachant/32/39450_2.png) [@amoebachant](https://forum.babylonjs.com/u/amoebachant)\
**Post date:** [January 13, 2026, 5:12pm UTC](https://forum.babylonjs.com/t/gui-line-connected-to-a-control-linked-to-a-mesh-with-higher-zindex-got-clipped-at-random-place/61796/6 "2026-01-13T17:12:43Z")

</div>

Unassigned @amoebachant on January 13, 2026, 5:12pm UTC


