The referenced script on this Behaviour (Game Object 'Main Camera') is missing!
Hi,
I know, there is always a lot of questions about this error BUT I didn't succeed to fix it with the previous answers...
So, please, let me explain.
I'm working with the Hololens tech. Recently, I have updated from HoloToolKit to MRTK V2 (new SDK provided by Microsoft and the community). My app worked with HoloToolKit, Unity and 2017.4. I updated for MRTKv2 and 2019.2 (recommended).
I have some scripts that use the camera position. In my previous app, Camera was BiCamera (GameObject), child of Basic (GameObject). And my BiCamera was tagged as MainCamera. Right now, my camera was Main Camera (with a space between the 2 words), tagged MainCamera, child of MixedRealityPlayspace. This camera is provided by the MRTKv2. I can't change the settings.
So, when I'm in a Play mode I have this message in yellow :
The referenced script on this Behaviour (Game Object 'Main Camera') is missing!
And when I move my Main Camera in order to simulate a walk of the user (Hololens = augmented reality), I have this message in red :
NullReferenceException: Object reference not set to an instance of an object
TextSpeedUI.Update () (at Assets/Scripts/TextSpeedUI.cs:23)
I think the second message is linked to the first... My script TextSpeedUI needs the camera.transform to calculate walking speed (in fact not directly, he finds the public variable from another GameObject, but this GameObject requires Camera.transform).
TextSpeedUI.cs 23
if (sd.isActiveAndEnabled && sd.Steps.Count > 4)
{
xzSpeed = (sd.Steps[sd.Steps.Count - 1].localMinPosition - sd.Steps[sd.Steps.Count - 4].localMinPosition) / ((sd.Steps[sd.Steps.Count - 1].t - sd.Steps[sd.Steps.Count - 4].t));
txt.text = (xzSpeed.magnitude * 3.6).ToString("0.##"); // speed in km/h
}
sd comes from public StepDetector sd;
which is at the beginning of my script TextSpeedUI.cs
And my script StepDetector.cs
calls public DataManager dm;
In my DataManager.cs
script, I call at the beginning :
public Camera Cam { get; private set; }
And in void Start :
Cam = Camera.main;
I hope I'm clear... I think it's an error in the name or other small error, but I don't understand...
Thank for your help.
Answer by AnelorGui · Oct 16, 2019 at 02:09 PM
I've solved by myself (just remove the component). It seems that it doesn't have consequence on my scene...
Your answer
Follow this Question
Related Questions
UIText Always Face My Camera ...PhotonNetworking 0 Answers
CameraController (object reference not set to an instance of an object) 1 Answer
There is no 'Animation' attached to the "Camera" game object, but a script is trying to access it. 0 Answers
Camera Switch Error 2 Answers
c# - error CS0103: The name `hit' does not exist in the current context (cardboard switching) 1 Answer