Change Variable with scene.registerAfterRender

Hello everyone,

Is it possible to change a variable that is outside of scene.registerAfterRender? For instance, in the PG below, can “test” be set to true within scene.registerAfterRender so that the sphere’s position changes?

For the particular issue I’m trying to solve, the variable has to change within scene.registerAfterRender, and the true/false statement has to be applied outside of it. I’m just not sure if this is possible :thinking:

https://www.babylonjs-playground.com/#02DQ3R

Yup this would totally work :slight_smile:

Hello @sebavan,

Good to know that I’m on the right track with this! However, when the variable “time” reaches zero, and the variable “test” switches to true, the sphere does not move. :thinking:

1

the variable test is changing but the code if test… does not run anymore as it only runs before register…

You should make it a function and call it everyFrame or better, only if test changes.

I see, that makes sense. Here’s my attempt at that with a function called “check.” Still no effect. I have limited programming experience, so I’m sure there’s something I’m still missing.

https://www.babylonjs-playground.com/#02DQ3R#1

You should call check in the render loop : https://www.babylonjs-playground.com/#02DQ3R#2

1 Like

Perfect! I didn’t see that it was outside of the render loop. This was a tremendous help, thanks! :smiley: :+1: