im atempting to dissable an object. specificaly the cinimachine camera. (just for a second) when ever i do it gives me this error
- nullreferenceexception: Object reference not set to an instance of an object CameraFollow.Update () (at Asset/script/CameraFollow.cs:31)
CameraFollow being one of the scripts dissabling the object.
May i note that i am dissabling it from a seperate object with the code
GameObject.Find(“CM vcam1”).SetActive(false);
the error doesnt effect anything on the surface but im worried it will cause internal problems later.
in laymans terms can somone explain to me what this error means. (cause im dumb and when i researhed it i didnt understand what it was saying)
(this is like my 6th thread asking questions i should probobly know the answers to by now)
Some notes on how to fix a NullReferenceException error in Unity3D
- also known as: Unassigned Reference Exception
- also known as: Missing Reference Exception
http://plbm.com/?p=221
The basic steps outlined above are:
- Identify what is null
- Identify why it is null
- Fix that.
Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.
1 Like
thank you so much xD
so im thinking it has somthing to do with the gameobject.find?
but everything seems to be called corectly.
im 25% sure that NullReffrenceException errors have to do with a reffrence not calling anything but im not sure.
///
ok ignore all of that
but i still dont understand.
i fixed it but i dont understand how.
this is what i did.
i switched from
GameObject.Find"CM vcam1").SetActive(false);
to
public GameObject CMvcam1;
//then in the editor dragged in CM vcam1
CMvcam1.SetActive(false);
on a semi-related note
when i try to set a Vector3’s value it never lets me
formats iv tried
(0,0,0)
(0,0,0,)
(0, 0, 0,)
(0, 0, 0)
iv had this problem in multiple scripts and for weeks now
(any reason for this? also ik it doesnt relate to this thread much at all but i didnt want to start a whole new thread just to ask a question like this)
Speculation is not really a substitute for engineering. Believe it or not, with a simple Debug.Log() you could PROVE if that is or is not the problem. That’s how you engineer.
Also, http://plbm.com/?p=248
You can either set a new Vector3 or modify an existing one like this:
using UnityEngine;
public class Vector3Tests : MonoBehaviour
{
public Vector3 myVector;
void Start()
{
//make a new Vector3
myVector = new Vector3(1.0f, 0.5f, 0);
//set the x y z components of an existing Vector3
myVector.Set(1.0f, 0.5f, 0);
}
}
You’ll find more information about what you can do with a Vector3 in the docs:
https://docs.unity3d.com/2020.2/Documentation/ScriptReference/Vector3.html
Click on whatever functionality you find interesting, and It’ll show you how to use it.
Good luck!
ok wow thank you both, that really helped me