- Home /
prefab null not instantiated: simple example not working?
Hi,
i can't instantiate my prefab, i read through the topics in the forum but i did not find any solution. Here is what i did :
-add a plane and a character to the scene,
-put them in an empty in "Hierarchy".
-Then, i created a prefab in Project, and i dragged and dropped the empty into this prefab.
-I then removed the empty from Hierarchy, and attached this script to the main camera :
function Start () {
//var instance : GameObject = Instantiate(Resources.Load("Prefabs/total", GameObject));
//var instance : GameObject = Instantiate(Resources.Load("total", GameObject));
var instance : GameObject = Instantiate(Resources.Load("total"));
//instance.transform.position = Vector3.zero;
}
function Update () {
}
But i have this error :
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) UnityEngine.Object.Instantiate (UnityEngine.Object original) I tried to put the prefab in a folder, or just in "Project", but i have got the same result. Any idea? ThanksArgumentException: The thing you want to instantiate is null.
Answer by CostelloNicho · Nov 22, 2012 at 09:54 PM
Place the prefab, that you are trying to instantiate, inside a folder called Resources not Prefabs.
Here's a link: Resources.load
Agreed or make a public variable of type Transform and assign the prefab in the Inspector and use that variable in place of the Resources.Load()
Thanks, yes indeed! The folder's name has to be "Resources", i did not understand that, Thanks!
Answer by alti · Nov 19, 2015 at 11:45 AM
For me, the issue was accidental and pretty stupid. I had applied the script to the object I wanted to do the instantiating, and then I also had it applied (not sure how or why... autopilot?) to the object that I wanted to instantiate.
So A was going to instantiate B, but on A I had the instantiate script, and I had it on B as well. The simple fix was: A was going to instantiate B. B was not going to instantiate another B, so B did not have the script. Only A had the instantiate script.
Your answer
Follow this Question
Related Questions
Follow and Instantiated Object 0 Answers
how to instantiate prefab with Resources.Load ? 4 Answers
Associate objects to a prefab 1 Answer
instantiating vertically 2 Answers
How to Add Y Axis Offset to transform.localPosition on an Instantiated Prefab? 2 Answers