Babylon GUI Editor, is it possible to update text value downloaded from snipppet server?

Good morning :slight_smile:
In my project I need small menu with Score and Time counter. I decided to use GUI Editor. Is it possible to update TextBlocks?
How to get text from TextBlock?
It’s my small example of GUI structure: https://gui.babylonjs.com/#3BJZ94#8

my code to get snippet:

let advancedTexture = AdvancedDynamicTexture.CreateFullscreenUI('GUI', true, this.scene);
let loadedGUI = advancedTexture.parseFromSnippetAsync('3BJZ94#8');
let scoreValue = advancedTexture.getControlByName('scoreValue');

You can use scoreValue.text to get and set the text, but you need to make sure that your GUI is finished loading first thou, e.g. using await like below. :slight_smile:

1 Like

Thanks, I’ve tried this solution, but I’m using TypeScript, so I can’t get .text field because it doesn’t exist on type ‘Control’

This is solution for typescript:
if (scoreValue instanceof TextBlock) scoreValue.text = '00001';

Or since you know it’s a TextBlock you can just cast it:

let scoreValue = advancedTexture.getControlByName('scoreValue') as BABYLON.GUI.TextBlock;
scoreValue.text = "00001";
1 Like