I am fairly new to unity and have made a basic VR maze game. It works well but I wanted to add some script to reload the scene when you finish. The problem is, when the scene reloads I get an error that says
"No GvrViewer instance found. Ensure one exists in the scene, or call GvrViewer.Create() at startup to generate one.
If one does exist but hasn’t called Awake() yet, then this error is due to order-of-initialization.
In that case, consider moving your first reference to GvrViewer.Instance to a later point in time.
If exiting the scene, this indicates that the GvrViewer object has already been destroyed.
UnityEngine.Debug:LogError(Object)
GvrViewer:get_Instance() (at Assets/GoogleVR/Scripts/GvrViewer.cs:43)
"
However, I do have a gvrviewer attached to my main camera. Here is the script I’m using to restart the scene:
public class SignPost : MonoBehaviour
{
private bool created = false;
DetectObject detectSign;
//public string GoToScene;
void Awake()
{
if (GvrViewer.Instance == null)
{
GvrViewer.Create();
created = true;
}
}
void Start()
{
if (created)
{
foreach (Camera c in GvrViewer.Instance.GetComponentsInChildren())
{
c.enabled = false; // to use the Gvr SDK without adding cameras we have to disable them
}
}
}
void Update()
{
detectSign = GameObject.FindWithTag(“MainCamera”).GetComponent();
GvrViewer.Instance.UpdateState();
if (GvrViewer.Instance.Triggered && detectSign.DetectSign == true)
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
I’m using a raycast to see if I’m looking at the sign I have at the end of the maze. If it’s detected and you click on it, it should reload the scene. The error generated is from the GvrViewer.cs script. I have the GvrViewer attached as a child to my main camera as well as the GvrReticlePointer.
Thanks for any help, if I need to provide more info I can do that.
Thanks!
