- Home /
Instantiate Prefab Gameobject vs Transform
I have a problem with the instantiate of a prefab. when i use the type Transform then all objects are shown and placed on the Hierarchy. But when i change the type to GameObject only one is made. I use Unity 5.6. On all examples it should work? Why ?
public Transform myCube;
for (int z = 0; z < 20 ; z++) { Vector3 point = new Vector3 (1, 1, z * 3); Instantiate (myCube, point, Quaternion.identity); }
I copied your code, tried Transform and GameObject versions, both works the same.
Answer by Woltus · Jun 23, 2017 at 06:19 PM
After changing prefab type in code You have to reasign prefab in inspector. If you don't this will spawn only one copy.
Answer by rnb-it · Jun 24, 2017 at 08:17 AM
Thanks,
Unfortunate mistakes, when I change in C# the type, the inspector does not automatically change also. And i used the same name voor the prefab and object. Now it's working.
Your answer
Follow this Question
Related Questions
Instantiate Prefab in another Prefab 0 Answers
Instantiate buttons , each with a unique positioning 2 Answers
How to instantiate random object in a panel ? 2 Answers
Destroy() not working on prefab instance 2 Answers
transform.Translate code isn't working 0 Answers