How to modify text contents of a GUI dynamically after parsing from snippet server

I have a GUI created using the GUI tool - https://gui.babylonjs.com/#MMWSUI#47

I load this in my playground using

var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI", true, scene);
let loadedGUI = await advancedTexture.parseFromSnippetAsync("#MMWSUI#47"); 
let exitButton = advancedTexture.getControlByName("ExitButton");
const backgroundBox = advancedTexture.getControlByName("BackgroundBox");
backgroundBox.isVisible = false;

exitButton.onPointerClickObservable.add( () => {
        console.log("Exit Button on Menu was clicked");
        backgroundBox.isVisible = false;
});

I’d like to do something like

advancedTexture.modifyControlByName("DescriptionText", "Updated Text Goes Here!!!");

I can’t find anything like modifyControlByName - is there a way to achieve this?

You can use getControlByName() to get the control and then set its text property: here’s a quick example to change the text to “Hello!” :slight_smile:

2 Likes