De-Panther / unity-webxr-export

Develop and export WebXR experiences using Unity WebGL
https://de-panther.github.io/unity-webxr-export/
Apache License 2.0
1.06k stars 111 forks source link

Entering VR via Script #268

Closed majortomL closed 1 year ago

majortomL commented 1 year ago

I am building an application in which I switch between two web pages, both of which have WebXR frames. So from the first one, in VR, I jump to the second one using a redirect. Upon arrival and loading finished in the second page, I want that one to automatically enter VR mode. I have tried:

Are there any indications on a best practice for achieving this? Is it possible at all? What am I missing?

P.S.: All these automated ways also do not work when page 2 is just launched standalone, and not via page 1.

EDIT: I've investigated further now. Tested on Edge and Chrome (same but different) with Rift S, and it all seems to work when I have not been using WebXR for the 30-90s prior to attempting the automatic ToggleVR() call. Could this be a problem on my side? I need this automatic toggle to work even after just having quit a webXR application...

De-Panther commented 1 year ago

It's part of the WebXR spec. The user must do an action(click/touch/etc...) to enter XR mode. Similar to open fullscreen...

There's a work in progress spec for WebXR Navigation, that would allow navigation between WebXR pages on the same domain, without exiting XR mode. But I think that it's only supported on Quest and it's experimental, so you need to enable a flag

majortomL commented 1 year ago

I get the action part. What I am wondering is why that does not work when I trigger the same exact action from a script. In additio, there is a method you provide in WebXRManager, ToggleVR(), that does just that, but does not seem to fulfill its purpose - is this just for dropping out of VR? How do I use this stuff properly?

...about the WebXR Navigation spec, could you provide me with a link or documentation? I can't seem to find anything myself...

De-Panther commented 1 year ago

As I wrote, "It's part of the WebXR spec. The user must do an action(click/touch/etc...) to enter XR mode. Similar to open fullscreen..." If the user is not the one who initiated the action, then it won't work. Calling a script to enter XR mode with no user click on the page, won't work.

ToggleVR doing that, but you need to call it from a user click.

WebXR Navigation - https://github.com/immersive-web/navigation