Whenever I start the game, even though all my code is in Javascript and i get no errors before starting the game, it gives me this error
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs)
NewBehaviourScript.Update () (at Assets/NewBehaviourScript.js:156)
when I double click it, it brings me to this line of code which works when I use it inside the game
if (mouse_position.y>mousePrevY transform.position.y != -6.785039){
//if there is an egg below?
if (Physics.Raycast (Vector3(transform.position.x-1,transform.position.y,transform.position.z), Down, 3)){
canmove=0;
} else if (Physics.Raycast (Vector3(transform.position.x+1,transform.position.y,transform.position.z), Down, 3)) {
canmove=0;
} else {
canmove=-1;
}
}
how do I solve this glitch?
I think Unity compiles some (or all) JavaScript code to a Boo equivalent (but I’m not sure on this) which might explain the error text.
Judging by the error, I would guess that mouse_position is null. Can you do a check if that’s the case?
Debug.Log("Is mouse_position null? " + (mouse_position == null));
if (mouse_position.y>mousePrevY transform.position.y != -6.785039){
I suppose it’s also possible “Down” is null so check that as well. Not sure if that’s the error message you’d get from that though.
at all times it says false, and the Down variable is Down = transform.TransformDirection (-Vector3.down); so i wouldnt think it would be null
Javascript is implemented with Boo (same author).
–Eric
ok, well the error happens whenever I create an object with this script but as soon as I move any objects by clicking and dragging (part of my script not with the editor) the errors stop until I create a new object again
Can you please post the object’s full source code and the line number of the error? Thanks.
EDIT: I think this isn’t an issue on the side of Unity glitching; I think it’s just a minor logical oversight in your algorithm.
Recently i had same problem. It seems that its caused of bad declaration of variable. Without declaring its type.
I don’t think there’s a Vector3.down, is there?
At one point Vector3.down (and left, and back) was deprecated. It’s apparently not deprecated anymore (or it’s the longest process of removal ever, though it’s not listed in the docs), but in any case, -Vector3.up = Vector3.down.
–Eric