Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

UNet Networking with Oculus Rift - Scene Switch Problem

Discussion in 'AR/VR (XR) Discussion' started by MikeKnite, Jul 17, 2015.

  1. MikeKnite

    MikeKnite

    Joined:
    Jan 24, 2015
    Posts:
    8
    Hi everyone,

    My friend and I are making a game in Unity 5 and we have noticed a problem upon using Unity's built-in networking system (UNet or Legacy, I don't know what it is called now). When I would try transitioning from the editor's menu scene, which is offline, to the online Main game scene, the game view stays in the offline Menu game and freezes. However, I can still control my vehicle when I view it in the scene, and my friend can connect via Hamachi, but his screen also freezes when he tries to connect.

    Below is a picture of the set-up of the menu scene.
    Beginning Scene.png

    I have two OVRCameraRigs, one in the offline scene, and one in the online scene. The one in the offline scene seems to take control and not let the one in the main scene show up.

    In the pictures below, the first picture with the Menu Camera is in the offline scene and the second picture is in the online scene which is frozen with the Menu Camera from the offline scene being displayed.
    OVR Camera Rig.png
    Main Scene.png
    I have disabled the components in the prefab that need to be disabled on the server side, and enabled the components in the prefab that I need on my client side. The OVRCameraRig in the main scene is there, but it is not able to override the other camera, even though that is not my intention. I just want that menu scene camera disabled and the Tank's camera to show up in the rift/game view. I assume that the offline scene would have the camera disabled upon one person joining or hosting the game and allow the Tank's OVRCameraRig to display in the rift/game view, but maybe I'm wrong and that camera is always visible.

    Has anyone else experienced issues using UNet (or Legacy Networking) with the Oculus rift and if so, have you found a workaround with this problem? Or, am I just making a simple mistake?
     
  2. Demozo

    Demozo

    Joined:
    Aug 19, 2014
    Posts:
    20
    Add a script to the offline camera rig and a method which overrides OnStartClient and disable/destroy the Offline camera rig. This allows the online rig to take control as it's the only one there. This is likely to cause an unpleasant VR experience however because of the sudden switching to the online rig.
     
  3. MikeKnite

    MikeKnite

    Joined:
    Jan 24, 2015
    Posts:
    8
    I tried doing what you said by making a script to the offline camera rig and overriding the OnStartClient method, but it still seems to freeze on the offline scene. I then tried overriding the OnStartClient in my CustomNetworkManager script (which takes in a parameter), but it seems to only disable it for a split second upon transitioning from offline to online scene and then freezing with the offline scene in the game view again.
     
  4. Demozo

    Demozo

    Joined:
    Aug 19, 2014
    Posts:
    20
    You can also change the depth of the online rig. On the Camera component there should be a "Depth" property/field. The offline rig would still be active though and will keep rendering, I think.

    Try overriding "OnStartLocalPlayer()" in your player object then use "Destroy(GameObject.Find("Menu Camera"))" to get rid of it. This should destroy the offline camera when the player has spawned.
     
  5. MikeKnite

    MikeKnite

    Joined:
    Jan 24, 2015
    Posts:
    8
    I tried changing the depth, but it still just froze the offline camera in the game view, so I don't think that the camera's properties are even being carried over, it's just freezing on that offline scene view. I also tried disabling/destroying the Menu Camera GameObject, but the same screen-freezing happens.

    I found a temporary solution where I can just use a main camera in the offline scene (not a Camera Rig) and transition to the Online scene, which would contain a Camera Rig, and the camera and scene switch would work just fine. But, I would like both scenes to be in the rift, rather than have one scene contain a Main Camera and the other have a Camera Rig. In addition with this temp solution, I would have to make the oculus rift a part of the desktop (Extend Desktop to HMD option) rather than the Direct HMD access where I can view the game on my computer and rift.
     
  6. Demozo

    Demozo

    Joined:
    Aug 19, 2014
    Posts:
    20
    How about using the offline camera rig as online rig when the online scene gets loaded? So you just move the offline rig to wherever the online rig is supposed to be (parent it).
     
  7. MikeKnite

    MikeKnite

    Joined:
    Jan 24, 2015
    Posts:
    8
    That's what I tried doing at one point, however, the offline camera rig does not show up in the online scene, only in the offline camera scene. So, when I try accessing the Menu Camera in the online scene, it would give me a NullReferenceException because it doesn't appear to exist in the online scene.

    I think it is something to do with transitioning between two Camera Rigs since I can do a main camera to Camera Rig transition in two different scenes fine.
     
  8. MikeKnite

    MikeKnite

    Joined:
    Jan 24, 2015
    Posts:
    8
    So, I decided to come back to networking after I was working on non-networking parts of the game and very bizarre things start happening. One of four things (possibly even more) happen so far when I use the oculus rift in HMD mode in the viewer:

    1) Unity crashes
    2) It goes to the online scene and my prefab is visible and controllable in the scene view, but for some reason shows this screen in the game view:
    What The Heck.png
    3) Or same as above but different image:
    What the Heck 3.png
    4) Or this one (The closest I can get to portray what I want which is the cockpit of the tank in the gunner's seat):
    What the Heck 2.png

    This is very strange and I started testing with networking after I updated to the newest patch, so maybe the patch may have something to do with it, but I don't see anything with Oculus Rift/networking addressed in the "Patch Fixes" log related to my issue. Also, I have two CameraRigs in the game. One will be activated in the client only when the host player joins and the player who joins the host player will have the other CameraRig activated in the client. Could this be a potential problem somehow, even though one will always be activated and the other will be deactivated on a player's client?
     
  9. MikeKnite

    MikeKnite

    Joined:
    Jan 24, 2015
    Posts:
    8
    Ok... I figured it out after three weeks. I'll post the solution for anyone who encounters a similar problem in the future.

    It seems like you have to make a prefab for the cameraRig which has an empty parent object. The reason for this is that you would want to disable the RightEyeAnchor and LeftEyeAnchor because just enabling the entire CameraRig seems to have problems in the current version of Unity and setting an empty game object as the parent will allow you to enable these anchors when loading the online scene. You also can't enable it right away or else you would get results of what I get in the above post.

    So, I had to add a Network Identity and a script to the prefab which would have a slight delay in enabling the Left and Right eye anchors upon loading the online scene.

    Code (CSharp):
    1.  
    2. GameObject getParent;
    3.  
    4.     public override void OnStartLocalPlayer () {
    5.         getParent = GameObject.Find ("OVRCameraRigGunnerOrDriver"); //the name of the CameraRig below the empty parent object in the hierarchy
    6.         StartCoroutine(DelaySlightly(0.01f)); //this is the delay amount I set, could be more or less
    7.     }
    8.  
    9.     IEnumerator DelaySlightly(float seconds) {
    10.         yield return new WaitForSeconds (seconds);
    11.         getParent.transform.Find ("LeftEyeAnchor").gameObject.SetActive(true);
    12.         getParent.transform.Find ("RightEyeAnchor").gameObject.SetActive(true);
    13.     }
    14.  
    I hope this helps anyone who tries to transition between scenes with UNet using the Oculus Rift.