Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by byBrickDaniel · Oct 13, 2021 at 07:33 AM · vroculus

Loading a new scene in unity make OVRManager throws errors

I have oculus integration vr 32 in unity 2021.1.16.

If I open a scene, play it with oculus link cable it works fine.

But if I open another scene, either just choosing another scene in unity or load a new scene from in the game, it starts throwing this error: MissingReferenceException: The object of type 'OVRCameraRig' has been destroyed but you are still trying to access it.

I have an OVRCameraRig prefab in each scene (which has OVRCameraRig and OVRManager) which is oculus own prefab.

I suspect that something lingers in OVRManager when I switch scenes. How do you use the OVRManager? Do you create it in 1 scene and then mark it for "DontDelete" or is there something that must be made in OVRManager to stop this error?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rh_galaxy · Oct 13, 2021 at 10:23 AM

I have never tried having those in every scene so I can't answer on that. I have a GameManager script attached to CameraHolder object as a singleton do not destroy object. I don't even use OVRManager or the OVRCameraRig to keep code compatible with non-oculus versions. I use a normal camera with a TrackedPoseDriver added to the same object like in the image. However should I add OVRManager and OVRCameraRig it would be to the CameraHolder object.

alt text

In my Awake() in GameManager I setup everything once and keep it when switching between scenes (I only have two scenes, Menu and Game). Maybe this can give you some ideas at least.

 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.XR;
 using UnityEngine.InputSystem;
 using System.Threading;
 public static GameManager theGM = null;
 public CameraController theCameraHolder;

 //first code to run
 void Awake()
 {
     //singleton
     if (theGM == null)
     {
         theGM = this;
     }
     else if (theGM != this)
     {
         //enforce singleton pattern, meaning there can only ever be one instance of a GameManager.
         Destroy(gameObject); //<- this makes OnDestroy() be called and
         //we don't want to deinit everything there (leave it empty).
         return;
     }

     //the rest is done once only...
     DontDestroyOnLoad(gameObject);

     bool bInited = InitOculus();

     if (!bInited)
     {
         bNoVR = true;
         Screen.SetResolution(1280, 720, true);
         Debug.Log("Error initing VR, continue with no VR");
     }
     else
     {
         Screen.SetResolution(864, 960, false);
     }

     //set thread prio
     UnityEngine.Application.backgroundLoadingPriority = UnityEngine.ThreadPriority.BelowNormal;
     Thread.CurrentThread.Priority = System.Threading.ThreadPriority.AboveNormal;

     //init to black screen
     theCameraHolder.InitForMenu();
     oFadeMatCopy = new Material(oFadeMat);
     oFadeBox.GetComponent<MeshRenderer>().material = oFadeMatCopy;
     StartFade(0.01f, 0.0f, true);

     //set audio out setting
     if (!bNoVR) AudioStateMachine.instance.SetOutputByRiftSetting();
     AudioSettings.OnAudioConfigurationChanged += AudioSettings_OnAudioConfigurationChanged;
 }

 private void AudioSettings_OnAudioConfigurationChanged(bool deviceWasChanged)
 {
     if (!bNoVR) AudioStateMachine.instance.SetOutputByRiftSetting();
     else AudioStateMachine.instance.SetOutput(0);
 }

 //start of oculus specific code
 bool InitOculus()
 {
     try
     {
         Core.AsyncInitialize("200555...."); //appid
         Entitlements.IsUserEntitledToApplication().OnComplete(EntitlementCallback);
         Users.GetLoggedInUser().OnComplete(LoggedInUserCallback);
     }
     catch (UnityException e)
     {
         Debug.LogException(e);
         UnityEngine.Application.Quit();
     }

     bOculusDevicePresent = true;
     return true;
 }

 void EntitlementCallback(Message msg)
 {
     if (msg.IsError)
     {
         Debug.LogError("Not entitled to play this game");
         UnityEngine.Application.Quit(); //it is possible to remove quit while developing
     }
     else
     {
         Debug.Log("You are entitled to play this game");
     }
 }

 void LoggedInUserCallback(Message msg)
 {
     if (msg.IsError)
     {
         Debug.LogError("No Oculus user");
     }
     else
     {
         //save ID, and user name
         szUserID = msg.GetUser().ID.ToString();
         szUser = msg.GetUser().OculusID;
         Debug.Log("You are " + szUser);
         bUserValid = true;
     }
 }


ovr1.jpg (330.7 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

212 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trouble Creating a Basic Oculus and Vive Reticle 0 Answers

Unity Input and Oculus Rift with Touch Controllers in Unity 2018.3.7f1 1 Answer

Oculus Go: Unity project is incompetable 0 Answers

How can I change "IK position weight" of finalIK ? 0 Answers

VR Oculus quest and collision 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges