- Home /
C# Resources.Load loading empty object
Hi,
I already checked online pretty much everywhere google allowed me to see, so here is my unanswered question. I am trying to load dynamically some content, based on a xml file, who give me the name of the "prefab" I am supposed to load.
I have my "Resources" folder. My prefabs are in that folder. I load my object using the following code :
Tile tile = ((GameObject)Resources.Load(pathToLoad, typeof(GameObject))).GetComponent<Tile>();
My "Tile" object seems valid, and I can do some stuff with it. However, the loaded object has none of its elements. All my prefabs have at least a visible render part, plus several other elements in it, such as other element with alternate renders elements.
The thing is, that the loaded object is empty. None of the attached elements are present in the prefab, and the default element has no render either.
Any idea why that happen ?
Answer by idrop · Oct 03, 2013 at 12:16 PM
Have you tried instantiating the prefab?
Instantiate(Resources.Load(pathToLoad, typeof(GameObject)));
Answer by venusboysatish · Oct 03, 2013 at 05:38 PM
Resources.load will only fetch you the reference. in your case, it will only fetch the reference to the prefab. you must instantiate a game object using that prefab and then do .GetComponent() on that game object. doing .GetComponent() on a prefab will of course give you null.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do I make prefab follow a gameobject?(C#) 1 Answer
Taking a screenshot in iOS/Android and save to file as well as Texture? 2 Answers
Issues with instantiated prefabs 1 Answer