Need help turning on and off the ARscene/ Camera

I am currently working on a project that upon completion pops up a UI and removes xrweb to essentially turn the camera off and AR scene. I now need to add in reset functionality that will then turn the camera and scene back on, so I am adding xrweb back into the scene. It was working a few days ago but now is causing some bugs and headaches. Is there any other way to essentially turn on and off the camera and AR scene? I would normally just refresh the page to restart it but the client doesn’t want the loading screen to come back up.

Hey Declan! What issues are you running into with xrweb?

You might try using XR8.pause() and XR8.resume() and covering up the paused camera feed with some 2D UI.

3 Likes

@Evan that seems like it will be a much better solution than what I am doing now. The project I am doing is a self hosted project being developed on VS Code with React and TypeScript. Do you know what I need to import to be able to use XR8 properly?

@Declan_Johnson XR8 is automatically added when the 8th Wall library loads (from the apps.8thwall.com… script tag). Usually good to guard your code to make sure it’s on the window before you try to access. Example

const onxrloaded = () => {
  // Do XR8 stuff here
}

// Wait until the XR javascript has loaded before making XR calls.
window.XR8 ? onxrloaded() : window.addEventListener('xrloaded', onxrloaded)

If you already initialized the xrweb component in your AFrame scene then XR8 is already on the window - but never hurts to code defensively :slight_smile:

2 Likes

Regarding the type declaration, I would just use a generic type:

declare let XR8: any

For reference: A-Frame: React - Multiple Scenes | 8th Wall Playground | 8th Wall

2 Likes

So currently i am getting back a message that says β€œ[XR] Pause cannot be called at this time.”

Never mind, I got it working. This was a problem not attached to this code, thank you!

3 Likes

how did you fix the β€œ[XR] Pause cannot be called at this time.” ?
i keep getting it after the xrloaded event and even after i check the XR8.isInitialized()

For me this was occurring because the scene was re-rendering right before I called the XR8.pause() function. I am working in react and there was a small call that was breaking things. Not sure if that helps or not, but that is what was happening to me.

1 Like