No GvrViewer instance found when a scene reloads

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!

Silly question I know, but are you sure that the code you have there is being executed? Have you added Debug.Log calls to the methods to make sure they are executing when you expect them to?

Also consider loading (and reloading) the maze as an additive scene, so camera is never unloaded. Because essientially all you are trying to do is move the camera’s transform back to the beginning position and reset a couple vars back to the start value.

joejo, I did add some debug lines and it showed things were being executed but I was still getting strange errors.

Selzier, That is really cool. I like how that is set up.

I solved it by using a trigger method with the event trigger script. I think the script I was using with the GvrViewer code was interfering with the way it’s called when the scene reloads. Thanks again for the help!

Hello @ , could you go into a bit more detail how you solved the issue. Almost the entire video above is going over my head. And I too am a beginner. I ran the debug.log too and as you observed, all the methods Start,Update and Awake were called in my case too.