x


Null reference Exception - but it's all there

I reordered prefabs, sounds, materials and everything else in my game project folder, using unity (i've not done this using windows explorer). Now i keep getting the "Null reference exception" error even if every game object is correctly linked to every referenced prefab or sound or anything else. I tried evrything, rename scripts, rename prefabs, relink evrything, but nothing works. What can i do?

more ▼

asked Jul 16 '12 at 10:58 PM

Mz3D gravatar image

Mz3D
81 10 30 43

What is the Null reference coming from (code?) are you using Resources.Load? or GameObject.Find()?

Jul 16 '12 at 11:49 PM highway900

It comes from a GameObject.Find() in a script! What can i do?

Jul 17 '12 at 07:30 AM Mz3D

Have the GameObjects been placed in your scene? Or are you using scripts to load the objects prior to calling GameObject.Find() ?

Jul 17 '12 at 11:31 PM highway900
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I recently tackled something similar and this may be your problem.

GameObject.Find('objectName') -- Will only find GameObjects that you have created in your scene or dragged from your prefabs into your scene.

Resources.Load('prefab') -- Will Load a prefab from your resources folder in your prefab section, if this does not exist you simply need to create a new folder named resources and move the prefab in to this folder. After loading the prefab you can then Instantiate the GameObject 'prefab' from which you have loaded.

You can now use GameObject.Find('prefab') now that the GameObject has been loaded.

more ▼

answered Jul 17 '12 at 11:48 PM

highway900 gravatar image

highway900
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x261
x193
x128

asked: Jul 16 '12 at 10:58 PM

Seen: 366 times

Last Updated: Jul 17 '12 at 11:48 PM