hello to all
I was presented this error
but I do not understand what is the cause …
how can I solve it?
hello to all
I was presented this error
but I do not understand what is the cause …
how can I solve it?
Well, like others said without seeing the code it’s hard to give a clear advice, however i try to explain what might cause thie error.
I guess you used an untyped variable to store a float value or any other kind of value type. An untyped variable is automatically typed as “object”. Value types (floats, ints, structs, …) have to be “boxed” when they are stored in an untyped variable. Boxing means that the value is placed on the heap. The system will allocates memory so it can be treated like an object.
On the other hand when you assign an untyped variable to a valuetype, the system has to read out the actual value from the referenced memory address and copy it into the value typed variable. This is called unboxing. The problem is that an untyped variable can be null. If the system tries to unbox a variable that is null, a null reference exception occures.
So you probable have a variable like this:
var someVar; // untyped variable
which is null and you try to use it as value type which will make the system unbox the null-reference:
// example
transform.position = Vector3(someVar,0,0); // unboxing to float --> error if someVar is null
To fix this you should:
#pragma strict” at the top of your script.The first point enforces the second.
Unity can not find the object you want to create ,check ur code carefullyc.check if u attached ur prefab to a public variable from inspector if u using prefabs
What is line 180 of your control.js script? Unboxing means the runtime is trying to convert an object from one class to another.
– Graham-DunnettWe need the script that is causing the error otherwise we can't help.
– ashjackOpen up your script called control.js, then go down to line 180 and copy and paste that section of code into here so we can help you.
– oliver-jones