Question by
Stadob · Sep 11, 2016 at 11:15 AM ·
gameobject
Instantiate() creates two GameObjects in scene
Hello
with this code attached into object
void Start()
{
GameObject o = new GameObject("test");
Instantiate(o);
}
script creates two gameobjects after run like this
any ideas? Im sure script is called only once
clonegameobject.png
(5.8 kB)
Comment
Best Answer
Answer by AurimasBlazulionis · Sep 11, 2016 at 11:48 AM
GameObject o = new GameObject("test");
also creates a game object. You do not need to call Instantiate
as it creates a copy of a referenced game object in a current scene. Instantiated is needed to spawn prefabs, not empty game objects, because prefabs do not exist in scene and empty game objects you create like above do exist.
Holy macaronni!! I totally forgot this behavior... now i feel really dumb. You are of course right... Thank you
Your answer
