Replacing one mesh with another, for many different meshes in a hierarchical scene?

I found this

This doesn’t deal with children but I imagine I could do

  if (this.oldMesh && this.oldMesh.getChildren) {
    const children = this.oldMesh.getChildren();
    children.forEach(child => {
      child.parent = newMesh; // Transfer each child to new mesh
    });
  }

But then I’m worried about race conditions if I try to do this for multiple meshes at the same time, especially if they are in the same hierarchy structure. Is there a standard way to replace a mesh?

your code here is correct and fully synchronous so it should be all good. Please share a playground if you find any issues with it.