How can we determine if our visionOS Unity application has lost focus?
Usually we use Unity’s provided functions like OnApplicationFocus and OnApplicationPause. But it does not seem like they function the way we would expect, as we don’t see them being triggered when a user opens the main menu on Apple Vision Pro, or when they resume our application.
Is your app using PolySpatial? If it is, you can subscribe to an event in VolumeCamera called WindowStateChanged to get a callback whenever the volume camera window gets or loses focus.
If your app is not using PolySpatial (i.e. Metal) OnApplicationFocus and OnApplicationPause should work, as far as I know. Please submit a bug and a repro case if those are not working for you when in Metal app mode.
I’ve spoken with the engineer who is working on OnApplicationFocus in visionOS. OnApplicationFocus needs some bug fixes but will eventually work in PolySpatial and Metal - in PolySpatial it should trigger once all windows are closed.
In the meantime, I’ll make a task to add a public-facing note or docs to indicate that it currently does not work. Let us know if there’s any issues with getting WindowStateChanged to work!