Quest VR: Save player coordinates before going in stand-by

I’m writing a Escape Room type of game for the Quest (2, 3) and there’s only one small thing left to do: preventing a player from walking out of a room (and into another room or outside the player area).

I’ve got this partly solved already. Whenever a player tries to walk through a wall, he’s teleported back a little - preventing him from actually going through that wall. But a problem arises when he takes of the VR goggles. When he does, the Quest enters stand-by mode. A player can then simply walk outside of a room and when he puts the goggles back on he will be in a place where he is not supposed to be. Reason being of course is that all scripting (and thus all checks) is suspended when the Quest is in stand by.

Now the easiest way would be to enable “Run in Background” in the Player Settings. Unfortunately, that setting is not there in XR projects.

So my thought of solving this, is to detect when the Quest wants to enter stand by mode, save the player’s world coordinates and when the Quest exits stand by mode, teleport the player to these coordinates. I’ve tried using OnApplicationPause/OnApplicationFocus, but neither are fired when the Quest enters stand-by mode.

So my question is: is there another way to detect the Quest going to sleep?

Accurately detecting when the user takes off/takes back on the headset is a major pain even with native support. I would discourage you from relying on this for crucial gameplay features.

What we did was implement a “safe area” concept in which, depending on which quests the user has already solved, determines in which areas the player can “legally” be. If they are outside that area, they are teleported back to the closest allowed region.

If your game has detectable proofs that the room was escaped correctly, like if there are triggers to open one of the doors between areas, you can use those as confirmation that a player is allowed to be in the new space. Combine that with tracking the last valid location, and you would hopefully be able to return them to the original room at a location you’re fine with.