UE-59712 - WorldToMeterScale problems with SteamVR and Play in Editor

I reported a bug UE-59712 where the WorldToMeterScale sometimes snapped back to the default value if the framerate jumped for example from 90 to 60 in SteamVR Play In Editor mode and I finally found the cause of this bug. In Play In Editor mode there are always at least 2 active Worlds, the Editor World and the Game World but only one instance of the FSteamVRHMD class. The WorldToMeterScale value is updated on the FSteamVRHMD during UWorld::Tick()->FSteamVRHMD::OnStartGameFrame() and the value is used again in FSteamVRHMD::OnBeginRendering_RenderThread() ->FSteamVRHMD::UpdatePoses() to calculate the position/orientation of the camera. Now for most cases this works without a problem, but if the framerate drops for example from 90 to 60 it can happen that the UWorld::Tick() of the Editor World is executed between the UWorld::Tick() of the game world and the FSteamVRHMD::OnBeginRendering_RenderThread() of the game world. Which means it overrides the WorldToMeterScale value of the Game World and replaces it with the one of the Editor World which then leads to the camera pose being updated with the wrong WorldToMeterScale value.

Here is a short Log spaced out by FrameIndex which shows the bug (line 22):

[14.36.21:723][ 92]FSteamVRHMD::OnStartGameFrame FrameIndex 2093 WorldToMeterScale: 100.000000 EditorWorld
[14.36.21:723][ 92]FSteamVRHMD::OnStartGameFrame FrameIndex 2093 WorldToMeterScale: 38858.023438 GameWorld
[14.36.21:729][ 93]FSteamVRHMD::UpdatePoses FrameIndex 2093 WorldToMeterScale: 38858.023438 GameWorld

[14.36.21:734][ 93]FSteamVRHMD::OnStartGameFrame FrameIndex 2094 WorldToMeterScale: 100.000000 EditorWorld
[14.36.21:734][ 93]FSteamVRHMD::OnStartGameFrame FrameIndex 2094 WorldToMeterScale: 38858.023438 GameWorld
[14.36.21:739][ 94]FSteamVRHMD::UpdatePoses FrameIndex 2094 WorldToMeterScale: 38858.023438 GameWorld

[14.36.21:744][ 94]FSteamVRHMD::OnStartGameFrame FrameIndex 2095 WorldToMeterScale: 100.000000 EditorWorld
[14.36.21:745][ 94]FSteamVRHMD::OnStartGameFrame FrameIndex 2095 WorldToMeterScale: 38858.023438 GameWorld
[14.36.21:756][ 95]FSteamVRHMD::UpdatePoses FrameIndex 2095 WorldToMeterScale: 38858.023438 GameWorld

[14.36.21:760][ 95]FSteamVRHMD::UpdatePoses FrameIndex 2096 WorldToMeterScale: 38858.023438 GameWorld
[14.36.21:761][ 95]FSteamVRHMD::OnStartGameFrame FrameIndex 2096 WorldToMeterScale: 100.000000 EditorWorld
[14.36.21:761][ 95]FSteamVRHMD::OnStartGameFrame FrameIndex 2096 WorldToMeterScale: 38858.023438 GameWorld

[14.36.21:771][ 96]FSteamVRHMD::OnStartGameFrame FrameIndex 2097 WorldToMeterScale: 100.000000 EditorWorld
[14.36.21:771][ 96]FSteamVRHMD::OnStartGameFrame FrameIndex 2097 WorldToMeterScale: 38858.023438 GameWorld
[14.36.21:774][ 97]FSteamVRHMD::UpdatePoses FrameIndex 2097 WorldToMeterScale: 38858.023438 GameWorld

[14.36.21:783][ 97]FSteamVRHMD::OnStartGameFrame FrameIndex 2098 WorldToMeterScale: 100.000000 EditorWorld
[14.36.21:783][ 97]FSteamVRHMD::UpdatePoses FrameIndex 2098 WorldToMeterScale: 100.000000 GameWorld <------------------
[14.36.21:783][ 97]FSteamVRHMD::OnStartGameFrame FrameIndex 2098 WorldToMeterScale: 38858.023438 GameWorld

[14.36.21:794][ 98]FSteamVRHMD::OnStartGameFrame FrameIndex 2099 WorldToMeterScale: 100.000000 EditorWorld
[14.36.21:795][ 98]FSteamVRHMD::OnStartGameFrame FrameIndex 2099 WorldToMeterScale: 38858.023438 GameWorld
[14.36.21:806][ 99]FSteamVRHMD::UpdatePoses FrameIndex 2099 WorldToMeterScale: 38858.023438 GameWorld

[14.36.21:810][ 99]FSteamVRHMD::OnStartGameFrame FrameIndex 2100 WorldToMeterScale: 100.000000 EditorWorld
[14.36.21:811][ 99]FSteamVRHMD::OnStartGameFrame FrameIndex 2100 WorldToMeterScale: 38858.023438 GameWorld
[14.36.21:828][100]FSteamVRHMD::UpdatePoses FrameIndex 2100 WorldToMeterScale: 38858.023438 GameWorld

Thank you for sharing this! I’m using 4.25, and while testing SteamVR in PIE the WorldToMeterScale node wasn’t changing the perceived scale at all. But everything is fine in a Standalone build or non-editor packaged build. I would’ve spent a looong time troubleshooting the PIE problem without your post :slight_smile: