How to copy the mesh collider of a child to parent?

Good day, does anyone here knows how to copy a mesh collider of a child to the parent?
you see In picture 1 where we have a gameobject that doesn’t have a mesh collider but it has a child underneath. And as inspect the child ( picture 2) it has a collider. What I want to do is copy that mesh collider to the parent in the script. I tried to do it by using the code

        GameObject cloner;     
      MeshCollider Mcoll;
 
     
Mcoll=_loadedGameObject.GetComponentInChildren<MeshCollider>();
     
      cloner = Instantiate(_loadedGameObject, placementPose.position, placementPose.rotation);
   
   
cloner.AddComponent(Mcoll.GetType(MeshCollider));

but the last line doesn’t work, it says ‘MeshCollider’ is a type, which is not valid in the given context

cloner.AddComponent(Mcoll.GetType(MeshCollider))


You can’t generally copy or move Components (like Colliders) around.

What you can do is make a new MeshCollider on the parent object, then assign the Mesh from the child MeshCollider to it, then Destroy() the child MeshCollider.

1 Like