A-Frame Entity Pause ↔ three.js Render Loop: Interaction Question
0 reputation · 07 May 2021, 21:23 UTC
0 reputation · 07 May 2021, 21:23 UTC
The goal is to clarify whether A‑Frame should automatically pause the three.js render loop when every entity reports a paused state.
In A‑Frame 1.x+ the render loop continues to run even after components call this.el.pause() on all entities, and the framework does not provide a built‑in mechanism to stop rendering based on those pause flags.
Does pausing all entities guarantee that no further three.js frames are rendered? Should A‑Frame expose a flag or event that lets developers tie the render loop to the collective pause state of entities?
34775 reputation · 08 May 2021, 09:11 UTC
In A‑Frame 1.x, this.el.pause() on an entity only stops that entity’s component tick callbacks, animations, and event listeners. The scene’s render loop, driven by THREE.WebGLRenderer, continues to call renderer.render(scene, camera) on every requestAnimationFrame tick. Therefore, pausing every entity does not guarantee that no further three.js frames are rendered.
The framework is designed for immersive VR and AR where continuous head‑tracking and frame timing are critical. Stopping the render loop would break XR sessions and frustrate users. The pause state is intentionally scoped to entity logic, not to rendering.
// In a browser console
const renderer = document.querySelector('a-scene').renderer;
let frameCount = 0;
renderer.info.render.frame = 0;
setInterval(() => {
console.log('Frames rendered:', renderer.info.render.frame);
}, 1000);
Even after calling entity.pause() on all entities, renderer.info.render.frame will continue to increment.
scene.renderer.setAnimationLoop(null) or replace the default loop with your own requestAnimationFrame logic.scene.pause() and scene.play() will pause/play the renderer automatically. This is still experimental.renderer.setAnimationLoop(null) does not stop XR frames; you must call xrSession.end() to fully stop.It would be useful for developers who want a single event to stop rendering when the entire scene is idle. A common pattern is to dispatch a custom event, e.g., all-entities-paused, when the application has paused every entity, and then listen for that event to call scene.renderer.setAnimationLoop(null). Until A‑Frame 2.0 stabilizes the Scene.pause API, this pattern is the recommended workaround.
To give you the most accurate guidance, could you let me know if you are running inside a WebXR session? That changes how you should stop the render loop.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.