Why createInstance() doesn't affect children, but clone() does

Hi everyone,

When a Mesh has children meshes and we call clone() on parent Mesh then both parent and children meshes will be cloned.

But when we call createInstance() on same parent Mesh, then instance only for parent Mesh will be created.

If we want to create an instance with all children we have to run ‘for loop’ over original children, create instances for them and assign parent instance for all children instances.

Are there any benefits from using instances in this cases? Or it makes sense not to struggle and use .clone()? If I understand correctly, clonned mesh is still more optimized approach than creating new mesh from scratch? At least clonned mesh is not fully functional because it requires at least .makeGeometryUnique() for some manipulations (creating instances for example).

Also, parentMesh.isVisible=false; doesn’t affect children. Makes sense in most cases, but probably there is a way to control this behavior?

Here is a playground that demonstartes situation from my question: Babylon.js Playground

Hey so in reverse order:

  • parentMesh.isVisible = false will only hide the parentMesh but if you call parentMesh.setEnabled(false) then you should get what you need
  • clone can be applied on all the hierarchy because a clone is a complete independent object whereas an instance (while being really faster) is also a bit more limited (can’t have its own material, share everything but TRS with source, etc…) So creating an instance must be done really purposefully. But if it works for your use case, please use instances :smiley:
3 Likes

Checked it in my playground. Seems like there is no such method:
parentBox.setEnable is not a function

Hi S!
Um, a little typo happened. setEnabled

1 Like