- Home /
Object Refererence not set yada yada...
I never entirely understood this error, I just know it's bloody irritating, but here's the code it's complaining about:
var graphicsComponent: Transform;
var cameraComponent: Transform;
function Start () {
if(graphicsComponent.networkView.isMine){
GetComponent("FPSInputController").enabled = true;
GetComponent("CharacterMotor").enabled = true;
GetComponent("MouseLook").enabled = true;
cameraComponent.camera.enabled = true;
cameraComponent.GetComponent("MouseLook").enabled = true;
cameraComponent.AudioListener.enabled = true;
}
}
function OnDisconnectedFromServer() {
DestroyObject(gameObject);
}
And the full error report:
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) OwnerControl.Start () (at Assets/Standard Assets/Scripts/Networking Scripts/OwnerControl.js:11)
Anyone know what I'm doing wrong?
Can you copy paste the full error report? It might mention which line & column had an issue. However, it's possible it has to do with your var declarations at the beginning or your DestroyObject call at the end.
It has something to do with your var declarations not being assign, i believe. In the UnityEditor, did you assigned the values to an object's transform/new transform? If not, that's probably your problem.
Answer by GradyLorenzo · Jun 09, 2013 at 08:00 PM
Yeah, here is is.
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) OwnerControl.Start () (at Assets/Standard Assets/Scripts/Networking Scripts/OwnerControl.js:11)
Please put this as an edit at the end of your original question.
Answer by Graham-Dunnett · Jun 09, 2013 at 08:10 PM
I believe that almost every line of your script could be wrong:
Line 5 - graphicsComponent
could be null if it is not set in the inspector yada yada
Line 6 - GetComponent
could return null if no FPSInputController
is added to the GO yada yada.
Line 7 - GetComponent
could return null if no CharacterMotor
is added to the GO yada yada.
Line 8 - GetComponent
could return null if no MouseLook
is added to the GO yada yada.
Line 9 - cameraComponent
could be null if it is not set in the inspector yada yada.
Line 10 - again, GetComponent
could return null yada yada.
Line 11 - cameraComponent
could be null if it is not set in the inspector or it might not have an AudioListener
yada yada.
Line 16 - what's gameObject
yada yada?
All of that is set in the inspector. I'll double check to make sure all of those references exist, though.
Line 16 destroys the object when the client disconnects. There's Network.Destroys on the appropriate objects, so I've done that correctly. All in all, the error's not affecting anything that I can see, I'm just OCD about it.
You've confirmed that line 11 is the one mentioned in the error report, so I think solving this will be trivial now.
Your answer
Follow this Question
Related Questions
NullReferenceException was thrown. Object reference not set to an instance of an object. 1 Answer
Object reference not set to an instance of an object. 0 Answers
NullReferenceException:"Object reference not set to an instance object" 1 Answer
(Javascript) Object reference not set to an instance of an object 1 Answer
Object reference not set to an instance of an object 0 Answers