VRTK how to find active CameraRig?

I am using the [VRTK_SDKManager] which provides a few different VR CameraRigs that the user can select from.

My question is after the user selects an SDK how do I know which camera rig is the active one?

More specifically I see the list of objects:

  • [VRTK_SDKManager]

  • Daydream

  • DaydreamCamearRig

  • OculusVR

  • OVRCameraRig

  • XimmerseVR

  • VRCameraRig

  • SteamVR

  • [CamearRig]

  • Simulator

  • VRSimulatorCameraRig

Notice that each camerarig gameobject has a non-standard naming convention, which makes it very difficult to just find the enabled “camerarig”.

So I was thinking about finding the “MainCamera” then getting it’s parents, however the hierarchy depth of the maincamera is also variable and not standardized.

How do I do this? Does the VRTK SDK have anything similar to OnChangeCameraRig() or GetActiveCameraRig()?

Thanks

VRTK_DeviceFinder.DeviceTransform(VRTK_DeviceFinder.Devices.Headset);

There is also an event when active sdk is changed:

VRTK_SDKManager.instance.AddBehaviourToToggleOnLoadedSetupChange

BTW I suggest joining the VRTK slack if you are actively using it and have more questions about VRTK or VR/Unity.

3 Likes

Thanks for the tip about AddBehaviourToToggleOnLoadedSetupChange, that worked very well.

However VRTK_DeviceFinder.Devices.Headset returns the headset’s transform and not the camera rig.

What I have done (that probably isn’t the most reliable way) is to add CameraRig tags to each of the camera rig gameobjects. then just do GameObject. FindGameObjectWithTag(“CameraRig”);

void Awake () {
    VRTK_SDKManager.instance.AddBehaviourToToggleOnLoadedSetupChange (this);
}
protected virtual void OnEnable() {
    var activeCameraRig = GameObject.FindGameObjectWithTag("CameraRig");
}
protected virtual void OnDestroy() {
    VRTK_SDKManager.instance.RemoveBehaviourToToggleOnLoadedSetupChange(this);
}

It works ok, but I would still like to know how to reliably get the VRTK camera rig without the assumption that it will have a tag.

Hmm… try: VRTK_DeviceFinder.PlayAreaTransform()

1 Like

Hello guys.

I saw this thread, and hoped you wouldn’t mind a quick question on VRTK and the Steam Camrig.
That I just cannot seem to get, or find an answer to.

I am working on quite a detailed outdoor scene. Using Standard asset manager, and after optimisation, I am getting decent frame rate.
And this is with post process stack profile.

But as soon as I swap to Steam Camrig, so I can switch to VRTK (porting) I haven’t even tried full motion.
My frames literally bottom out, going from smooth to an almost slide show.

And that is without the post processing profile added. When I do this it gets even slower.
I couldn’t even find how to extend the far clipping plane in VR camrig. So massive slowdown, and not even showing the distant scenery.

Quick question please. I hope you dont mind.
Is there any way to use VRTK with the Standard assets first person camera. I have tried but couldn’t get it to work.
Or is not, is there a way to speed up Steam VR camrig?

I really appreciate any help.
I have been banging my head up against this one now for weeks.
I made a post on the forums with no joy.

Thanks for any help.

PS, Or if there ane any links you knwo, that I couldn’t find.

Firstly, the best place to gather information on VRTK SDK’s inner workings is most definitely not here. There is an issues discussion board on thestonefox’s GitHub where the developers frequent and they can answer your question with higher certainty.

But, if I understand what you’re saying it’s that when Unity is using SteamVR standalone then it runs normally. However, when still using SteamVR but the camera is part of the VRTK camerarig then the game always (immediately) starts dropping frames…???

Does using the VR simulator cause the same issue??
Are you able to recover by stopping and dropping back to the editor?
What happens when you delete all VRTK releated objects after the issue occurs (may need to add a new camera…)?

Also I can remember back on Unity 5 my friend’s PC had trouble (occasionally) in a “back woods” scene with dense trees and hilly terrain. His PC would do exactly as you said and become a slide show for random short durrations.
Not sure how or if I ever fixed it, but by removing trees made the problem subside. And now in Unity 2017.3.0f2 they redid the tree system completely to accommodate VR headsets. If you have a high number of trees always visible then it’s possible that update could help…

Also just a thought, try changing the order (or removing everything except SteamVR) from the SDK Setups list under Player>VR Settings (recently renamed to XR Settings).

Make sure only SteamVR is there, then restart Unity and try again.

Hey.

And than you so much for both the reply, and the link to Github. I will check that it, I appreciate the information.

To be honest I never used the Steam camrig at all. Unless I used it for VRTK.
So just now, after mentioned it in your reply, I just disabled standard assets FPS cam, and brought steam camrig on.

Just looking round, It only dropped maybe between 2 to 5 fps. But that was with no post processing, AA, or decent clipping plane. The mountains in the distance were popping in and out as I looked around.
I cant understand why steam VR cam would have this almost bottleneck on performance, which really kicks in after VRTK.

Its why Im hoping if there was a way to use VRTK with standard assets fps cam.

I am not at all familiar with “VR simulator.” I never heard of it before you mentioned it.
What is is please?
Maybe that could help me.

You mentioned trees, but in standard assets fps cam its all good.
It just seems to be when I add VRTK.

I am completely baffled why no-one else has experienced the massive frames drop between standard assets FPS cam, and steamcamrig with vrtk.

Hello,

can we do the same Camera programming operations on the VRTK camera rig as the regular unity cameras?

For example my code has

ray = Camera.main.ScreenPointToRay(Input.mousePosition);

Camera.main.ScreenToWorldPoint(new Vector3(Screen.width - to.x, Screen.height - to.y, Camera.main.transform.position.z + 200.0f));

Can i do all these operations with the VRTK camera rigs camera?

Thanks

The vrtk camera that is referenced by the device finder should be the active (main) camera attached to the headset. So transforms should be synonymous between VRTK headset camera and Camera.main.