Switch to VR mode after user put a HMD on

Hello
Could you please help with this functionality :
“Switch to VR mode, after user wear HMD, exit VR when user takes HMD off”

I’ve tried to use “GetHMDWornState” function but i was unable to setup it properly.
Is it possible to create custom event on HMD worn state ? If so how to do it?
Kind Regards
Greg

This depends on the XR plugin you are using. When using UE5 and the OpenXR plugin, the only indication seems to be it setting FApp::HasVRFocus() to return true only when the app is focused.

The OpenXR spec does not have any way of directly indicating if the HMD is worn. The only indications it has is indirectly through the session state, which when visible or focused indicates that the user can see the app. Different runtimes may handle it differently, and may not transition away from the focused state even when the HMD is removed.