Instantiate a component creates a new game object?


If I instantiate a component, does it create the new component with a new game object or clone it in the same game object that the component cloned?

LineRenderer old = new GameObject().AddComponent<LineRenderer>();
LineRenderer line = Instantiate(old);

line has the same game object as old or his own game object?

Hi, yes, you don’t instantiate components in and of themselves - a component always needs a gameObject wrapper. What are you trying to do?

If you read the documentation - from 2019.4: "This function makes a copy of an object in a similar way to the Duplicate command in the editor. If you are cloning a GameObject you can specify its position and rotation (these default to the original GameObject’s position and rotation otherwise). If you are cloning a Component the GameObject it is attached to is also cloned, again with an optional position and rotation.

I just want to create another linerenderer by instantiate the old linerenderer and rotate the new around a random point of the old.

But, I noticed a shift between the two and I think it’s because of this stuff. I hope :smiley:
Thank you.