- Home /
Loading prefab programatically
Hi, Actually i am newbie to unity3d. I tried to load prefab programatically, but the loaded prefab is not visible. here is my code,
gameObj = Resources.Load("sample", typeof(GameObject)) as GameObject; Instantiate(gameObj, transform.position, Quaternion.identity);
Any kind of help to solve this problem is highly effective.Thanks in Advance.
regards, nonameagan.
Are you getting any error log when these lines are called..?Your resource 'sample' should be in a folder named Resources under Assets folder.
'Assets>Resources>sample'
The code is fine,dont change. Hope this helps...
I tried your script, and it worked just fine:
void Start() {
GameObject gameObj = Resources.Load("Bullet", typeof(GameObject)) as GameObject;
Instantiate(gameObj, transform.position, Quaternion.identity);
}
Check:
Check to make sure that your prefab is in the Assets/Resources folder.
Check to make sure the spelling of 'sample' is identical between the prefab and the script.
$$anonymous$$ake sure that the position of your object this script is attached to is visible to the camera.
$$anonymous$$ake sure it is not appearing inside of another object.
Check the hierarchy to see if the object is getting created at all.
If it is in the hierarchy but not visible:
Check to make sure the position it is created at is visible to the camera.
Check to make sure it is enabled. If the prefab is disabled, then the created game object should be disabled.
Check to make sure the renderer is turned on. Again check the original prefab as well as the scene object.
$$anonymous$$ake sure it is not inside another game object.
$$anonymous$$ake sure it doesn't have a scale of (0,0,0).
Hi, $$anonymous$$ay i know whether the prefab is an 3D Object created using Blender.
I Check with all these ,but it is not visible in the scene.
regards, nonameagan.