|
I am working on a script with C# and whenever I run my game, console pops up and says "Object reference not set to an instance of an object. Then when I click it to try and solve the problem, it brings me to this point in my script and I can't figure out what to do...
Could someone help me out? I will be continuously trying to find my answer on the Unity website.
(comments are locked)
|
|
Is that findgameobject function returning anything? It sounds like you're assigning a null response to that array. No it's not null it's just that Unity can't find the object to create and I don't know how to show which object.
Dec 19 '09 at 01:54 AM
Colin Vinson
I hink it has to do with sp2 not being properly initialized. Try something like GameObject [] sp2 = new GameObject[]; and then try the assignment from the findgameobject function. Google the error comes up win lots of examples and the common ones seemed to be arrays (or other variables) not properly initialized before assignment.
Dec 19 '09 at 04:04 AM
jester
Should I make a new line after GameObject[]; in "GameObject[] sp2 = new GameObject[];?
Dec 19 '09 at 04:39 PM
Colin Vinson
can you either include more code here or private message me more code? i can't reproduce that error. from google searches i'm near convinced it's an initialization error but i can't yet reproduce that error myself to continue helping you. here's one of many links that do similar array creation and returns that error when trying to access a member of the array that is actually null: http://www.velocityreviews.com/forums/t75867-static-problem-object-reference-not-set-to-an-instance-of-an-object.html
Dec 19 '09 at 07:37 PM
jester
(comments are locked)
|

Can you give the source for your entire script? Or at least the entire function if it's very long.
There you go that should be it. Unless you need more. I could do that. There is another part describing the object allSpheres. Do you need that?