- Home /
Error that I can not solve
hello to all I was presented this error
but I do not understand what is the cause ... how can I solve it?
What is line 180 of your control.js script? Unboxing means the runtime is trying to convert an object from one class to another.
We need the script that is causing the error otherwise we can't help.
Open 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.
Answer by Bunny83 · Dec 04, 2013 at 03:38 AM
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:
make sure you use "`#pragma strict`" at the top of your script.
type all of your variables.
The first point enforces the second.
Answer by belvita · Dec 03, 2013 at 10:46 PM
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
Your answer
Follow this Question
Related Questions
Boat script problems when changing platform to android 0 Answers
Animation script error 1 Answer
Console Error 1 Answer
Getting this error when trying to run a game on android 2 Answers