# C++ check is game in HMD (VR) mode

**URL:** <https://forums.unrealengine.com/t/c-check-is-game-in-hmd-vr-mode/424119>\
**Category:** XR Development\
**Tags:** unreal-engine, hmd, UE4, question, CPP\
**Created:** [May 2, 2018, 4:30am UTC](https://forums.unrealengine.com/t/c-check-is-game-in-hmd-vr-mode/424119 "2018-05-02T04:30:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_e10a6464](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e10a6464](https://forums.unrealengine.com/u/anonymous_user_e10a6464)\
**Post date:** [May 2, 2018, 4:30am UTC](https://forums.unrealengine.com/t/c-check-is-game-in-hmd-vr-mode/424119/1 "2018-05-02T04:30:13Z")

</div>

How do I check, in C++ code, whether the game is in VR mode?

I tried the following but it doesn’t work:

```
IHeadMountedDisplay *pHmd = nullptr;
if (GEngine) {
	pHmd = GEngine->XRSystem->GetHMDDevice();
}
if (pHmd->IsHMDEnabled()) {
	// we are in VR mode?
}

```

The above code thinks we’re in VR even when we are not.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e10a6464](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e10a6464](https://forums.unrealengine.com/u/anonymous_user_e10a6464)\
**Post date:** [May 2, 2018, 4:46am UTC](https://forums.unrealengine.com/t/c-check-is-game-in-hmd-vr-mode/424119/2 "2018-05-02T04:46:50Z")

</div>

To answer my own question, the following seems to work for 4.19 in editor mode (VR Preview) vs (New Editor Window):

```
IHeadMountedDisplay *pHmd = nullptr;
TSharedPtr<IStereoRendering, ESPMode::ThreadSafe> pStereo = nullptr;
if (GEngine) {
	pHmd = GEngine->XRSystem->GetHMDDevice();
	pStereo = GEngine->XRSystem->GetStereoRenderingDevice();
}
if (pHmd->IsHMDEnabled() && pHmd->IsHMDConnected() && pStereo->IsStereoEnabled()) {
	// in VR mode
}

```

Though now I wonder if this is the correct/official way to do it?

---

<div class="post-metadata">

**Author:** ![lab-one](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lab-one/32/780274_2.png) [@lab-one](https://forums.unrealengine.com/u/lab-one)\
**Post date:** [June 22, 2018, 9:32pm UTC](https://forums.unrealengine.com/t/c-check-is-game-in-hmd-vr-mode/424119/3 "2018-06-22T21:32:46Z")

</div>

From source code of node IsHeadMountedDisplayConnected

```
return GEngine->XRSystem.IsValid() && GEngine->XRSystem->GetHMDDevice() && GEngine->XRSystem->GetHMDDevice()->IsHMDConnected();

```

So your code is correct

---

<div class="post-metadata">

**Author:** ![The\_Regurgitator](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the_regurgitator/32/710746_2.png) [@The\_Regurgitator](https://forums.unrealengine.com/u/The_Regurgitator)\
**Post date:** [March 7, 2023, 12:57am UTC](https://forums.unrealengine.com/t/c-check-is-game-in-hmd-vr-mode/424119/4 "2023-03-07T00:57:57Z")

</div>

Note this is only sufficient to check if the HMD is connected and ready, not to tell if the game is running in VR. You need `IsHMDEnabled()` and/or `IsStereoEnabled()` for that .
