- Home /
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.
Answer by csciguy · Mar 08, 2011 at 03:08 PM
Try removing the leading slash in your path. "GameStuff/Prefabs/PlayerPrefab". You should not need to add the .prefab to PlayerPrefab.
Answer by DaveA · Feb 10, 2011 at 11:21 PM
Did you try putting .prefab on the file name? "/GameStuff/Prefabs/PlayerPrefab.prefab";
Answer by Shanlu · Apr 04, 2015 at 07:26 AM
if you want to load a prefab from script the complete code is given below
Object myPrefab ;
myPrefab =Resource.Load("coin");
//load the prefab .here coin is my prefab name and it is located at resources folder
//if you want to create the instance then instantiate(myPrefab);
Your answer
Follow this Question
Related Questions
What should a script contain? 1 Answer
Script is working incorrectly. (rotation) 1 Answer
Spawning Player After Player Choice. 1 Answer
Distance betwen two objects.Error,bug,etc. 2 Answers
loading a scene seems to be slower 0 Answers