- Home /
Using Resources.load with a variable
Im tring to load prefabs from the resources folder based on a string variable item1 that is based in another script. The code I have works if I put in the name of the object directly instead of item1 eg "Gloves1". But when I try the code I have below I get the error "The thing you want to instantiate is null."
GameObject prefab = (GameObject)Instantiate(Resources.Load(item1, typeof(GameObject)));
You should provide more information about the scripts that are involved. It might be that the variable is not initialized at the time this line is executed. This can have several reason. However, in order to receive help you should post the scripts or at least the relevant parts of it.
Please provide more information. If you pull the string from another script, how do you initialize that variable?
Answer by hexagonius · Oct 03, 2015 at 03:38 PM
The gameobject you want to instantiate needs to be in the resources folder as a prefab, but no subfolder and needs to be called Gloves1.
Your answer
Follow this Question
Related Questions
Disable/Enable game object by clicking instantiated prefab during runtime 0 Answers
Find a variable using a string 1 Answer
Source Gameobject rendered when using prefab 0 Answers
Modifying/Calling Instantiated Objects 1 Answer
Help? Im trying to get my zombie prefab to spawn, but stop them spawning after a set spawn limit. 1 Answer