Unable to Scene.unregisterBeforeRender() successfully

I’ve either found a bug, or I’m not using this properly. Please see this playground. Pressing the spacebar should toggle the cube’s spinning off and on. Instead, it’s just getting faster as the method is re-registered every other time the spacebar is released.

This is because you’re registering an anonymous function and unregistering nothing (another anonymous function that is not registered, so it’s ignored)

Option 1.
Use a named function

Option 2.
Use Observables and track the returned Observer object that can then be used to remove the function again.

and with an Observable we can also use the “observer” property as the “registered” check

1 Like

Thanks for the quick reply! I was completely missing the () => my AI coding partner so cheerfully put in for me! :blush: