# Element calculatedHeight - wrong calculation

**URL:** <https://forum.playcanvas.com/t/element-calculatedheight-wrong-calculation/40950>\
**Category:** Help & Support\
**Tags:** ui\
**Created:** [October 7, 2025, 12:19pm UTC](https://forum.playcanvas.com/t/element-calculatedheight-wrong-calculation/40950 "2025-10-07T12:19:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramon](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/r/34f0e0/32.png) [@Ramon](https://forum.playcanvas.com/u/Ramon)\
**Post date:** [October 7, 2025, 12:19pm UTC](https://forum.playcanvas.com/t/element-calculatedheight-wrong-calculation/40950/1 "2025-10-07T12:19:41Z")

</div>

Hi,

Currently I am trying to get the correct height of a text element to relatively size the parent entity. However I am running into some issues.

The calculatedHeight is actually shrinking every time I log it while the text entity receives the same text.

I made a small project to reproduce the issue;  
[https://playcanvas.com/editor/project/1403005](https://playcanvas.com/editor/project/1403005)

```javascript
PopupScript.prototype.setPopup = function (id) {
    const data = PopupScript.popupData.find(entry => entry.id === id);
    if (!data) return console.warn('no popup data found for', id);
    if (data.activated) return;

    this.bg.element.anchor = new pc.Vec4(0, data.anchorY, 1, data.anchorY);
    this.entity.enabled = true;

    this.textEnt.element.text = data.text;
    setTimeout(() => {
        this.bg.element.height = this.textEnt.element.calculatedHeight + 0;
        console.log("height:",this.textEnt.element.height)
        console.log("calculatedHeight:",this.textEnt.element.calculatedHeight)
    }, 1000);

    // this.app.once('postrender', () => {
    // this.bg.element.height = this.textEnt.element.calculatedHeight + 0;
    // });

    if (data.activated !== undefined) { // if it is defined it means it shows only once. If it is undefined it will show everytime
        PopupScript.popupData.find(entry => entry.id === id).activated = true;
    }

    this.currentid = id;

};

```

Any ideas, how to fix this?

---

<div class="post-metadata">

**Author:** ![Ramon](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/r/34f0e0/32.png) [@Ramon](https://forum.playcanvas.com/u/Ramon)\
**Post date:** [October 15, 2025, 12:49pm UTC](https://forum.playcanvas.com/t/element-calculatedheight-wrong-calculation/40950/2 "2025-10-15T12:49:10Z")

</div>

Anybody?

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [October 15, 2025, 1:12pm UTC](https://forum.playcanvas.com/t/element-calculatedheight-wrong-calculation/40950/3 "2025-10-15T13:12:40Z")

</div>

Had a very quick look. I think the issue is the text entity is a child of the element that you are resizing so you are getting into some weird circular dependency of height calculation. Likely due to the child height being affected being set to stretch to the parents size.

Changing the text entity to be a preset of center anchor and pivot gets around that issue

[https://playcanvas.com/editor/scene/2341472](https://playcanvas.com/editor/scene/2341472)

---

<div class="post-metadata">

**Author:** ![Ramon](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/r/34f0e0/32.png) [@Ramon](https://forum.playcanvas.com/u/Ramon)\
**Post date:** [October 15, 2025, 3:22pm UTC](https://forum.playcanvas.com/t/element-calculatedheight-wrong-calculation/40950/4 "2025-10-15T15:22:36Z")

</div>

Thanks, that seems to work!
