IsHeadMountedDisplay returning false, running a packaged game with -vr command line argument

Reproduction Steps

  1. Create new C++ Project
  2. Create 2 new C++ classes: MyPlayerController and MyLocalPlayer
  3. Add the following code to log out the result of IsHeadMountedDisplayEnabled()

MyLocalPlayer.h

public:
	virtual FString GetGameLoginOptions() const override;

MyLocalPlayer.cpp

FString UMyLocalPlayer::GetGameLoginOptions() const
{
	UE_LOG(LogTemp, Warning, TEXT("LocalPlayer: VR: %d"), UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled());
	return Super::GetGameLoginOptions();
}

MyPlayerController.h

public:
	virtual void BeginPlay() override;

MyPlayerController.cpp

void AMyPlayerController::BeginPlay()
{
	Super::BeginPlay();

	UE_LOG(LogTemp, Warning, TEXT("PlayerController: VR: %d"), UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled());
}

Next:

  1. Create a Gamemode Blueprint and select MyPlayerController as the default Player Controller
  2. In the Project Settings select the Gamemode you just created as the default Gamemode class
  3. in Project Settings → General Settings, select MyLocalPlayer as the default Local Player class
  4. Compile and Package the project for Windows
  5. Right click on the .exe of the packaged game and add a shortcut
  6. Add the -vr command line argument to the shortcut (Target: “C:.…\WindowsNoEditor\MyProject.exe -vr”)
  7. With the HMD plugged in and SteamVR running, start the packaged game via the shortcut
  8. Have a look at the the logs (…\WindowsNoEditor\MyProject\Saved\Logs) and search for “LogTemp”

Result: IsHeadMountedDisplayEnabled returns 0 for false

Expected: IsHeadMountedDisplayEnabled returns 1 for true

Hello,

I apologize for the delay. I am looking into this issue and will respond back as soon as I have new information.

Thanks for your patience.

Hey AllJonasNeeds,

Apologies for the delay, we’ve recently moved offices and gotten the set up. Are you still experiencing this issue, and if so, have you checked to see if it is an issue in 4.14?

Thank you for your patience

Hey ,

I just tested it again with 4.14 in a new project following the reproduction steps in the original post. IsHeadMountedDisplayEnabled() ist still returning 0 for false.

For the project I am currently worknig on I have a workaround using my own function instead of IsHeadMountedDisplayEnabled():

bool UVRFunctions::IsGameInstanceInVR()
{
	return UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled() || FParse::(FCommandLine::Get(), TEXT("vr"));
}

Hello AllJonasNeeds,

I ran a quick test in blueprints to see if I could reproduce IsHeadMountedDisplayEnabled returning false when the headset is in use, however I could not reproduce this issue on our end. If you create a new VR template based project and add the blueprint from the attached image to the level blueprint (MotionControllerMap) and package the project out with the -vr command, do you still see this issue on your end?

Image:

118666-isheadmounteddisplayenabledhelp.png

I modified my project to include your Blueprint and added a Print String node on the Level’s BeginPlay node as well.

On Tick IsHeadMountedDisplayEnabled always returns true. But on BeginPlay inside the Level Blueprint IsHeadMountedDisplayEnabled returns false in a packaged project, that is started with the -vr launch option as outlined in the original post.

Edit: Here is an excerpt of the packaged project’s log, if anyone is interested in that.

[2016.12.15-08.45.38:693][  0]LogAIModule: Creating AISystem for world Map
[2016.12.15-08.45.38:693][  0]LogLoad: Game class is 'BP_Gamemode_C'
[2016.12.15-08.45.38:695][  0]LogWorld: Bringing World /Game/Map.Map up for play (max tick rate 0) at 2016.12.15-09.45.38
[2016.12.15-08.45.38:695][  0]LogWorld: Bringing up level for play took: 0.000909
[2016.12.15-08.45.38:696][  0]LogTemp:Warning: LocalPlayer: VR: 0
[2016.12.15-08.45.38:697][  0]LogTemp:Warning: PlayerController: VR: 0
[2016.12.15-08.45.38:697][  0]LogBlueprintUserMessages: [Map_C_1] BeginPlay HMDEnabled: false
[2016.12.15-08.45.38:697][  0]LogLoad: Took 0.024554 seconds to LoadMap(/Game/Map)
[2016.12.15-08.45.38:899][  0]LogLoad: (Engine Initialization) Total time: 2.33 seconds
[2016.12.15-08.45.38:899][  0]LogExternalProfiler: Found external profiler: VSPerf
[2016.12.15-08.45.38:899][  0]LogExternalProfiler: Using external profiler: VSPerf
[2016.12.15-08.45.38:916][  0]LogOcInput: OculusInput pre-init called
[2016.12.15-08.45.39:014][  1]LogRenderer: Reallocating scene render targets to support 2240x1260 NumSamples 1 (Frame:2).
[2016.12.15-08.45.39:156][  1]LogRenderer: Reallocating scene render targets to support 3024x1680 NumSamples 1 (Frame:3).
[2016.12.15-08.45.39:156][  1]LogBlueprintUserMessages: [Map_C_1] LevelTick HMDEnabled: true
[2016.12.15-08.45.39:426][  2]LogBlueprintUserMessages: [Map_C_1] LevelTick HMDEnabled: true
...

After further testing, I believe that this is working as intended. It appears that the begin play fires off before the HMD is enabled. If you place a delay after the begin play before calling “IsHeadMountedDisplayEnabled” you will see that it returns true. You could try using tick to check to see if it is enabled and stop when it returns true. I hope that this information helps.

Make it a great day

Wow. This fixed it for me. But it’s been 4 years! There has to be a right way of checking this.

Even the FPS template checks this on BeginPlay (see screenshot)! And I just tested, it’s TRUE in play-in-editor and FALSE when packaged there too (running with -vr)! Version Version: 4.25.4-14469661