To obtain a label’s updated dimensions after changing its text, wait until the label has processed or rendered the new content before reading its UITransform.
Change the label text
1 | const labelNode = this.node.getChildByName("LabelNode"); |
Replace LabelNode with the actual node name used by your scene.
Wait for the update
Scheduling the size read allows the label layout to refresh first:
1 | director.getScheduler().schedule(() => { |
For modern Cocos Creator code, also consider scheduleOnce or waiting until the next frame, depending on when your surrounding layout updates.