Forum Discussion
creat326
10 years agoProtege
multiple cameras
Hi
I have two different scenes in my game. One is the main menu with a OVRCameraRig #1 that works just fine.
The second scene, is the actual game. it is loaded additively to the first one and it also has a OVRCameraRig #2 on it.
When I load this second scene, the first thing I do is disable the #1 OVRCameraRig gameobject since it has different settings for layers and far distance and all that.
The problem is that when you load the second scene, things get nasty on the Gear VR (sometimes just freezes the game). Why? Well, it seems that since both have a OVRManager, it creates a problem.
Looking at the code, OVRManager allows for only one instance of it. So the problem is that when I load the second scene, internally it is still pointing to the old OVRManager but its gameobject was disabled.
If I don't disable it, then it takes the info from the #1 stuff and ignores the #2 and things begin to look messy, I believe it's getting rendered 4 times (2 per camera and 2 OVRcameraRigs)
In short, how can I load additively a new scene which also contains a OVRCameraRig, disable the first one and enable this second one without getting OVRManager into a mess?
I have two different scenes in my game. One is the main menu with a OVRCameraRig #1 that works just fine.
The second scene, is the actual game. it is loaded additively to the first one and it also has a OVRCameraRig #2 on it.
When I load this second scene, the first thing I do is disable the #1 OVRCameraRig gameobject since it has different settings for layers and far distance and all that.
The problem is that when you load the second scene, things get nasty on the Gear VR (sometimes just freezes the game). Why? Well, it seems that since both have a OVRManager, it creates a problem.
Looking at the code, OVRManager allows for only one instance of it. So the problem is that when I load the second scene, internally it is still pointing to the old OVRManager but its gameobject was disabled.
If I don't disable it, then it takes the info from the #1 stuff and ignores the #2 and things begin to look messy, I believe it's getting rendered 4 times (2 per camera and 2 OVRcameraRigs)
In short, how can I load additively a new scene which also contains a OVRCameraRig, disable the first one and enable this second one without getting OVRManager into a mess?
8 Replies
Replies have been turned off for this discussion
- PhyterJetHonored GuestMy guess is what's happening is that the OVRManage is a 'singleton' only one should ever exist, so I guess you should destroy the first before loading another scene. I'm sure someone else has solved this problem before.
the first thing I do is disable the #1 OVRCameraRig gameobject
Exactly when? this is important because the OVRManager and OVRCameraRig script perform actions in the Awake method, which will (probably) conflict with each other.
And the Awake method is called before the Start method.
Better explained here http://docs.unity3d.com/Manual/ExecutionOrder.html
or here http://answers.unity3d.com/questions/217941/onenable-awake-start-order.html
If you NEED 2 OVRCameraRigs then you should disable one of the OVRCameraRig objects in the scene editor, with the check mark option.
But you should never need 2 OVRCameraRigs, it makes no logical sense (unless you have two Oculus Rifts on the same computer, which I don't think is supported by the OVRServer)
In your case I would recommend having a separate scene for the main menu, and another for the actual game. It will make things simpler for Unity in general, but specifically the Oculus integration.
EDIT: I misread some of your post, gimmie a second - creat326ProtegeYeah only one should exist but inside the code it destroys automatically the other ones so it shouldn't be a problem.
The way I fixed is:
1) Never disable/destroy any OVRManager script. As soon as you remove it, when you reactivate it, your gear VR crashes.
2) Since you can't disable/destroy any, that means that even though in theory you could have it on multiple prefabs and they will autodestroy themselves, this is not true. Just remove OVRManager from any other prefab and scenes.
3) What sucks most, is that the original settings for OVRManager stick. So if for instance your first OVRManager has no head tracking, antialiasing and any other settings... all your future cameras on the game will have the same settings.
So you can't have different settings for your Main Menu UI camera and another for the game cameras. This is horrible.
There must be a way to achieve it by heavy modification of the OVRManager script but at this point I have to decide between trying to submit something to the vrjam or fixing bugs on not-my-code stuff :( - PhyterJetHonored GuestYou can modify settings in the OVRManager while it's running, from any other object.
this will get you a reference to the single OVRManager:OVRManager.instance
and you can modify all of it's public fields like:OVRManager.instance.usePositionTracking = false;
I think all of the OVRManagers public fields are listed from lines 313 - 378 in OVRManager.cs
Make sure you add this to the top of your script thoughusing Ovr;
Example: Toggles positional tracking when you hit A (Probably not the correct way, but it works)
using UnityEngine;
using System.Collections;
using Ovr; // need this for OVR
public class TogglePositionalTracking: MonoBehaviour {
void Update () {
if (Input.GetKeyDown (KeyCode.A)) {
OVRManager.instance.usePositionTracking = !OVRManager.instance.usePositionTracking;
}
}
}
This script can be attached to any gameObject - creat326Protegeyeah but that affects all cameras, that's the issue, the subject of this is: multiple cameras
btw, I forgot to mention i'm trying this on mobile sdk, not the pc version.
So if I want to have 2 cameras with a depth buffer so I can create some effects (like a rear mirror on a car), you are in trouble.
The script first doesn't allow for depth buffer (it's hardcoded into the rig script, as soon as you run into the device it modifies the order to its liking and also sets the camera to solid color no matter what you decided what was)
Also you don't want those cameras to use position tracking but you do want your main camera to use position tracking.
If you enable it for both, the mirror image will move as you rotate, which doesn't make sense. And that's exactly what the mess on OVRManager does.
It seems our only option is to use a single camera and remove tons of cool other features. - PhyterJetHonored GuestBut you can only ever render the scene from one camera? or one OVRCameraRig?
Can;t you just change settings before or after you switch between the main menu and the game? - paulovichExplorerIt is prety crazy that so far switching cameras by enable/disable as we do with regular cameras is not properly implemented.
- paulovichExplorerREading your text an idea came to my mind.
I've found teh way to switch betwen multiple cameras in scene, instead of disabling the OVRCameraRig, have all of the cameras OVRCameraRig enabled and enable/disable the TrackingSpace gameobject. This allow you to switch betwen cameras.
It alwo works if the object is instantiated after scene loading so it will work for networked games. aaa finally!! can´t believe this isn´t documented! - paulovichExplorerI've found that even if the cameras are disabled, when 4 or more OVRCamera Rigs are present in scene the framerate drops.
So what I'll do is to have one camera for the cenital stuff and for teh player instantiate an ovr camera Rig and move it according to different positions, because otherwise for each player in teh multiplayer room FPS collapse.
Please, make a proper camera switching for unity.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 8 months ago