How to compute the size for GUI mode "CreateForMesh"?

BBL GUI in 2D mode always use ‘pixel’ to compute size and display it on screen faultlessly. I wonder how to achieve it in 3D mode? What’s the calculation method used to get the fittest size in Mesh? Here’s the PG to show my doubts about the control size in 3D mode. Using ‘pixel’ to compute size and put it into 3D mode that’s so strange!! The control size never fit to mesh. It’s there any way use ‘metre’ as unit to compute?

I try to stick with % as it seems easier for building GUIs and also I don’t typically show a square GUI panel, although that is the size of the texture as a power of 2 (1024x1024 by default). This playground only works in 4.2 as this is not a constructor is throwing error in v5:
modal dialog | Babylon.js Playground (

That PG is from 2018 and I know there have been a lot of additions for fitting GUI, so wait and see if there are better ways to accomplish controls to fit to mesh.

Adding @msDestiny14 who can help with this.

hi @sebavan - I looked a bit more and the static factory method the “this” isn’t recognized.

The error in 5.x is from here:
Babylon.js/button.ts at e7b5cd8ce3a9a1cfdb463cd7a4122c58c7847693 · BabylonJS/Babylon.js (

Change was made here, but that was nearly a year ago! :smiley:
Creating a new focusable button gui element. · BabylonJS/Babylon.js@e73fbac (

edit: removing new keyword in front fixes it, but then technically it’s a breaking change (for somebody that mistakenly used “new” on a factory method!!). I think it’s OK to leave it, but pointing it out the possibly undesired side-effect.

edit2: the “Create” prefix is a clear enough indicator that new is unneeded - same as MeshBuilder, etc.

1 Like

Hey there!

Just like brianzinn said. % are the best way to get that the “responsiveness” you want in a texture adding. Now when you create for mesh you can specify a pixel size for that texture but I understand that can be confusing for your model size.

If you know you’re doing to be using a plane I have a cute little trick that we do in the GUI editor :wink: :
Create a plane of 1x1 and then scale your plane to your desired texture size.

    let textureSize = 1024;
    _textureMesh = BABYLON.MeshBuilder.CreateGround("GuiCanvas", 1, 1, 1, scene);
    _textureMesh.scaling.x = textureSize;
    _textureMesh.scaling.y = textureSize;
    let guiTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateForMesh(this._textureMesh, textureSize, textureSize, true);

The GUI editor is suitable for v5, my project is still using v4.2, i’m waiting for the final v5, because of the current v5 isn’t stable

The current release is as stable as v5 would be :slight_smile: most of the alpha let us basically finish some of the work in progress but all the existing features from 4.2 should be as stable as in 4.2.

When will you release the final V5? I’m looking forword to it :wink:

Adding @PirateJC for the release date

Late April 2022 is what we’re aiming at right now.