CreateScreenshot positions GUI TextBlock (linked with mesh) in a wrong way

Hello again,
I’m using CreateScreenshot method and I realized that the TextBlock GUI (that i linked to a mesh), in the outputted image is positioned in a wrong way.

Here I’ve made a simple playground – to avoid a sudden download on your computer i’ve commented the createScreenshot method —> https://playground.babylonjs.com/#9CRB6R#3

Playing with it, i found that the text GUI has a static offset position related to the mesh it is attached to (only when downloading the image).
So if you move the textBox, you’ll see that the textBlock output will change position.

While when it’s rendered on real time, it’s position as it’s supposed to, so at the center of the cube.

I’ve also put in the playground a GUI Multiline, to show that it’s not a general GUI problem, but in this specific case, it affects the GUI Textblock.

Is there something I’m missing in the options?

I also saw that if you delay a little bit with setTimeout, it seems to generate a correct image.
Is that the only workaround?

Thank you

1 Like

setTimeout is to be sure your scene has been fully initialized and rendered.

Without it for me, I am seeing only the clear screen color without anything else.

I am not sure how to repro what you experience :frowning:

1 Like

@sebavan ah… haha that’s weird. Maybe createScreenshot to be sure it creates everything apart from the device speed of compilation, network performance ecc, needs this empty setTimeout.

Without setTimout I have this behaviour:

(3000 is in the bottom of the screen).

I guess i’ll stick to setTimeout, since it get the works done :slight_smile:

Thank you!!

1 Like

You can also use scene.whenReadyAsync instead of setTimeout to wait for the the scene to be ready.
https://playground.babylonjs.com/#9CRB6R#4

4 Likes

Thank you @Blake !
I’m not a big fan of setTimeout, so i’ll follow your advice.
I’ve already tried and it renders everything nicely.

Have a great day :sun_with_face:

2 Likes