I'm having trouble tracking down a problem with SteamVR. Here is a quick way to set up an MWE:

  • Create a new Unity project.
  • Import the SteamVR package from the Asset Store.
  • Create the following script:

    using UnityEngine;
    public class CameraCreator : MonoBehaviour {
        private GameObject cameraObject;
        private void Start ()
            cameraObject = new GameObject("CameraObject");
            cameraObject.transform.position = Vector3.one;
  • Create an empty game object and add this script to it.

SteamVR seems to lock this object's position (and that of any other game object with a dynamically created camera component) to the origin. No matter what I try to do to change it (inspector; set it inside update; set it in a coroutine), it always ends up back at the origin at some point during the frame (I believe somewhere between LateUpdate and OnRenderObject, but I'm not entirely sure). Without data breakpoints I find this really hard to track down.

This behaviour isn't really a problem for my actual project, but I need to be able to create cameras and modify their positions in my unit tests, where I'm having the same issue.

Does anyone know what's causing this, or have any advice on how to track down the cause?

  • \$\begingroup\$ I tried your script and don't have any issues in Unity 2017.4.5f1. I tried adding Update() and move it up continously without any issues either. I made a new scene, added the [CameraRig] prefab, then an empty game object with your script and it worked. BUT, if this camera is the only camera in your scene, I suspect OpenVR may take control of it. Can you elaborate more? \$\endgroup\$ – Morten Jul 14 '18 at 9:21
  • \$\begingroup\$ @MortenAndersen I haven't added any SteamVR prefabs or components to the scene, I'll see whether that fixes it. I'm on Unity 2018.1, btw. \$\endgroup\$ – Martin Ender Jul 14 '18 at 9:23
  • \$\begingroup\$ Alright, I expanded my comment. I've also never had issues with a secondary camera used for rendering to the screen. But if it's the only camera, that may be issue. Perhaps try an older Unity version to see if it's a Unity bug. \$\endgroup\$ – Morten Jul 14 '18 at 9:25
  • \$\begingroup\$ I'm at a different PC now and can no longer reproduce it here. I'll have to do more testing next week. \$\endgroup\$ – Martin Ender Jul 14 '18 at 13:46
  • \$\begingroup\$ @MortenAndersen It turns out that the problem only occurs if you've actually got a Vive (or presumably some other headset) attached. And in that case it doesn't matter which cameras are added to scene, it just depends on the stereoTargetEye property of each camera object. See my answer for details. Thanks for looking into it though! \$\endgroup\$ – Martin Ender Jul 17 '18 at 12:19

As it turns out, SteamVR does start tracking all cameras automatically by default. The relevant property on the Camera object is stereoTargetEye, or "Target Eye" in the Inspector. So if you want to create a camera dynamically which isn't being tracked by SteamVR, you'll have to do:

var camera = cameraObject.AddComponent<Camera>();
camera.stereoTargetEye = StereoTargetEyeMask.None;

Likewise, you need to change this property in the Inspector for all cameras which are added to the scene via the editor, if you don't want them to be tracked.

I am a little surprised that None isn't the default value of this property.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.