x


Loading a prefab from script

public static string playerPrefab = "/GameStuff/Prefabs/PlayerPrefab";

Object pl = Network.Instantiate(Resources.Load(playerPrefab),
            new Vector3(0, 0, 0), Quaternion.identity, 0);

The only error I am getting is NullReferenceException, I figure this means that Resources.Load is unable to find my prefab, which is located in \Assets\Resources\GameStuff\Prefabs\PlayerPrefab.prefab. I've tried with \ instead of / etc.

more ▼

asked Feb 10 '11 at 07:53 PM

Adeny gravatar image

Adeny
21 3 3 6

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

2 answers: sort voted first

Try removing the leading slash in your path. "GameStuff/Prefabs/PlayerPrefab". You should not need to add the .prefab to PlayerPrefab.

more ▼

answered Mar 08 '11 at 03:08 PM

csciguy gravatar image

csciguy
59 3 3 4

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

Did you try putting .prefab on the file name? "/GameStuff/Prefabs/PlayerPrefab.prefab";

more ▼

answered Feb 10 '11 at 11:21 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

(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:

x3329
x1255
x297

asked: Feb 10 '11 at 07:53 PM

Seen: 4920 times

Last Updated: Feb 10 '11 at 07:53 PM