Two ways to copy a component (subtle differences)

Rolf Reinelt
Rolf Reinelt Member, Employee Posts: 2

A channel partner reported that

comp = GetRootPart().Components[0]

compCopy1 = ComponentHelper.CopyToRoot(comp)

compCopy2 = Copy.Execute(ComponentSelection.Create(comp))

CompCopy1 is faster, but creates the component with a very small offset.

Michael Janes reply was:
The component has a transform, and ComponentHelper.CopyToRoot creates a new component without a transform.  Personally, I think the transform should be copied to the new component, but I’m hesitant to change it because it could break existing scripts.  Instead, I added an example to the documentation. 

For your case, try the following:

comp = GetRootPart().Components[0]

compCopy1 = ComponentHelper.CopyToRoot(comp)

transform = comp.Content.GetTransformToMaster().Inverse

compCopy1.Transform(transform)

The channel partner confirmed this.

I have posted this here for future reference.