How to wait for a frame to execute

var target = new BABYLON.GUI.Ellipse();
target.width = “40px”;
target.height = “40px”;
target.color = “Orange”;
target.thickness = 4;
target.background = “green”;
advancedTexture.addControl(target);
target.isVisible=false;

//Wait for a frame
{
target.isVisible=true;
}

You can do:

window.setTimeout(() => target.isVisible = true, 0);

You could also use engine.frameId which is returning the current frame number: this counter is increased by one at each new frame.

1 Like

You could also use something along the lines of

scene.beforeRenderObservable.add(()=> {
     if (engine.frameId === frame) {
            target.isVisible = true
      }
})
1 Like

Cool,thanks

or scene.beforeRenderObservable.addOnce :slight_smile:

1 Like

addOnce won’t work if engine.frameId !== frame when it is called: the if won’t set the target visible and because we added the callback only once it won’t be reexecuted.

We would need a addOnceIf where we would provide the if condition along with the callback.

1 Like