Pause & Resume Engine

What is the recommended way to pause and then resume playcanvas? app.timeScale = 0; and app.autoRender = false; will not solve the issue I’m having.

The web AR project I’m working on has strange needs, including needing to switch back and forth between a 8th-wall/playcanvas game scene and a 8th-wall/aframe MCRS hologram scene. I’ve run into issues trying to accomplish that with the same 8th wall instance, so my current approach is to use two fullscreen iframes (one to house each scene) and switch back and forth between displaying them. However, there doesn’t appear to be an easy way to pause playcanvas (including all the document event listeners) without completely destroying the app.

Hi @spencer_pnt and welcome,

Yes, settings those properties to 0.0/false will disable rendering, will stop calling the scripts’ update() method and disable physics I think.

But any event handlers attached for e.g. input will continue to fire. You will have to manually handle those to detect when your app is paused and stop execution.

A common way is to have a global variable/object that is checked at the beginning of each input handler. If it’s set to false, then the app is paused, exit.

A more elaborate way is to detach all input handlers as soon as you fire an app wide app:pause event. And similarly re-attach as soon app resumes.

1 Like

Thanks for your reply, Leonidas. It turns out just pausing the engine wasn’t shutting all the 8th wall stuff down completely, so we’ve resorted to completely destroying the app, which works for our needs now.

app.graphicsDevice.clear({ color: [0, 0, 0, 0] })
app.graphicsDevice.clearShaderCache()
app.graphicsDevice.clearVertexArrayObjectCache()
canvas.style.display = 'none'

app.destroy()
app = null

canvas = null
devices = null

We added this functionality into a function to the bottom of the exported start.js

3 Likes