x


Prefabs are instantiated in editor but not in executable

I have a prefab (item) instantiated on the ground when an enemy dies. Everything works fine in the editor, but when I try building the project, nothing is spawned. All my prefabs are in the Resources folder (in the Assets folder). This is the code to assign the dropped item :

item = Resources.Load ("Prefabs/Weapons/LightMachineGun");

The output_log.txt file gives me a NullReferenceException.

Sorry if the problem is obvious. Thanks.

more ▼

asked Jul 17 '10 at 01:18 AM

Jeremy 2 gravatar image

Jeremy 2
57 5 5 12

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

item = Instantiate( Resources.Load(thing) );

Resources.Load returns an Object; that is, a reference to the object in the Project. You need to use Instantiate to create a copy in the Hierarchy.

more ▼

answered Nov 13 '10 at 04:07 AM

Loius gravatar image

Loius
10.9k 1 12 43

(comments are locked)
10|3000 characters needed characters left

Are the assets that are used by your prefab (model,textures etc.) also in the Resources folder?

more ▼

answered Jul 17 '10 at 05:26 AM

StephanK gravatar image

StephanK
6k 40 53 93

Once they are in the resources folder, do I have to load each one of them (audio clip, textures used by scripts, etc)?

Jul 17 '10 at 06:00 AM Jeremy 2

No, but they must be there, otherwise the prefab can't be instantiated.

Jul 17 '10 at 10:28 AM StephanK

Just as a test, I moved all my assets in the Resources folder and nothing happens. Thanks for the suggestion though.

Jul 17 '10 at 04:59 PM Jeremy 2
(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:

x1730
x1726
x1288
x685
x223

asked: Jul 17 '10 at 01:18 AM

Seen: 1457 times

Last Updated: Jul 17 '10 at 01:18 AM