createInstance creates an invisible instance of mesh

I am trying to create an instance of a mesh with const instancedMesh = mesh.createInstance();. But unfortunately, the new instance is not visible in my scene. However, when I put instancedMesh.showBoundingBox = true;, it shows the bounding box, but still the new instanced mesh is not visible. although the instancedMesh.isVisible and instancedMesh.isEnabled is true. I don’t know what is affecting the scene to not render the instance of the original mesh, although the createInstance() is actually creating an instance of the original mesh.

I can not show you the actual situation in the playground since the same code works fine in the playground but not working in my project.

It could be a winding problem with the material.

Try to set material.backFaceCulling = false. If the mesh does appear it means the winding is inverted. You can try to change the material.sideOrientation value to fix it (but createInstance should not normally needs such a change…).

1 Like

it does not work :pensive:

Maybe you’re freezing the material before the instance is created?

1 Like

I checked the mesh.material.isFrozen it returns false. So the material of the mesh is not frozen before the mesh is created

You didn’t hide the original mesh before creating the instance, did you?
Else, you didn’t mirror the mesh before creating the instance?
Else, you didn’t parent the mesh to a minus scaled root before creating the instance?
Else, you didn’t mirror your material on the source mesh?

Only other scenarios I can think of where you would see the bounding box but not the instance is if the visibility of the mesh is set to a small, non-zero value or if you created a material but didn’t implement instance support. Or are you just using a builtin-in material? And does the mesh have a skeleton? Or instance attributes? Also if you create the instance later after the mesh has been rendered try creating it right after creating the mesh for a quick test? :thinking:

1 Like

Wow! That’s a hell of a lot of assumptions and possibilities :dizzy_face: :wink:, isn’t it? @Ehtesham_Ahmad_Nadim, see how just much easier and more accurate our response would be if you would be able to reproduce in a PG. Else, I’m afraid you would need to check on all that (and more). There’s actually one more thing that cought my attention is when you say, “it works in the playground but not in my scene”. May be you also have some ‘specials’ towards the treatment of materials, registering to the buffer, post-processing, layerMasks, what do I know… :wink:
If you cannot reproduce in PG, I believe all that’s left is to break it down until you find where it breaks.