- Home /
The question is answered, right answer was accepted
Why is my instantiated prefab invisible ?
Hello, Unity Community!
I have this script attached to an empty game object:
void Start () {
_spawnPoint=GameObject.FindGameObjectWithTag("PlayerSpawn").transform.position;
_selectedShape=PlayerPrefs.GetInt("shape");
switch(_selectedShape)
{
case 1:
Instantiate(Resources.Load("circleMC_prefab"),_spawnPoint,Quaternion.identity);
break;
}
}
Basically, this should check what was selected in the previous scene, and according to that instantiate a specific prefab from my "Resources" folder, at a certain location determined by the "PayerSpawn" game object.
When I try to test it, the prefab is instantiated, I can see it in the editor, but it is invisible in the game! What's wrong ?
Does the prefab have a renderer component attached and enabled?
Also check that it is within the clipping planes of the camera
Ha! Silly mistake by me. The prefab is getting instantiated at PlayerSpawn's position, with a Z=-10. Needless to say the camera didn't see it. I'll gladly vote this as the correct answer, if you want to post it as one. Thanks for your answer. Cheers!
Answer by Kiwasi · Jul 05, 2014 at 07:23 AM
Are you sure the GameObject is in view of the camera?
Answer by Tanshaydar · Jul 04, 2014 at 10:18 PM
Instead of loading from Resources, I'd suggest to have GameObject list in your script and assign them to script (not the scene, but select the script in project view and assign the prefabs from there) and then instantiate them as gameObject_circle, _spawnpoint, Quaternion.identity
This can be difficult to maintain in certain circumstances. In this case I don't think using the resources folder specifically is the problem.
I can see how that would be the better option. However, I'm changing scenes often, without loading many prefabs, so it would just hinder my design process, in my opinion. $$anonymous$$aybe I didn't understand it properly.