Encountering an odd quirk in JavaScript, where a simple AnimationMixer.update(delta)
function only works when accompanied by a console.log statement:
// Here's one that works as expected
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
// Updating mixers...
Object.values(sandbox.models).forEach(x => (x.mixer && console.log(x.mixer.update(clock.getDelta()))));
}
// These ones do not work properly
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
// Updating mixers...
Object.values(sandbox.models).forEach(x => (x.mixer && (x.mixer.update(clock.getDelta()))));
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
// Updating mixers...
Object.values(sandbox.models).forEach(x => (x.mixer && void(x.mixer.update(clock.getDelta()))));
}
Furthermore, when attempting to play the animation using
AnimationMixer.clipAction(animation).play()
, it doesn't work unless I include the logging statement.
This behavior is quite perplexing - why does the mixer only update when its return value is logged?
I am unable to share all of the code due to its length and dependencies on external files.
Logging excessively is not a viable solution, as it can negatively impact game performance.