SteamVR locks position of dynamically created cameras

SteamVR locks position of dynamically created cameras

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.AddComponent();
        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?

Solutions/Answers:

Answer 1:

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.

References