Instance mesh source change

Hello, I am trying to change the source of the instanced mesh I did this playground
when you press on the middle sphere of the second clone it will change the material but the instanced mesh won’t change because its source isn’t the clone its the original model,
so is there are a way different then this way that I did in the second playground to change the source of instance

or is there are an option while I clone the model the source of instance in the cloned model will follow the meshes in the clone.

You can’t change the source of an instanced mesh, it’s a readonly property.

Why would you want to change the source in the first place? Instead, you should make an instance from the mesh you want to set as source of the existing instance.

the instances are already set from the model so I am not creating the instance in the code

Ok but why do you want to change their source parameter? If you need to do that, it means you don’t need those instances but you need other ones. So just delete these instances and create new ones from the right master mesh. Changing the _source property won’t work.

Having hard time understanding the issue…

So you have instances created in 3D software and loaded into a scene. You are cloning these instances inside the code. And when you change the material of the clone, the mesh from which you cloned (slash instance created in 3D software) will not change the material?

If above is correct, that’s expected behavior, as mesh.clone will not create an instance of the mesh (which will share properties with original mesh), it will just create a copy of that object with it’s own set of properties… Instead you could try using createInstance().

okay so in the above playground is a simple example of what I am doing in the local project

I have a model created in 3D software and that model has multiple meshes and the instance’s of them
I am cloning the model into 3 clones but the instance meshes of the clone are following the source of the original model, so when I change the material of mesh of 1 clone the instance in the clone won’t change material because the source not changing material,
I did try to change _sourceMesh it worked in the playground but in local the meshes of the original model is disappearing but everything in the inspector look fine like the meshes are enabled and the material is enabled
so i am asking if there are a way to change the source other then that way or a way to set material for the instance because there are not.
thank you anw

You can’t update mesh._sourceMesh, it’s a private property and even if it works in some cases it is not supported and will likely fail at some point: meshes you create by calling masterMesh.createInstance(...) on a master mesh can’t have a material different from masterMesh, it’s by design and a limit of the instancing feature.

If you want to copy some meshes and be able to use a different material for each copy, use masterMesh.clone(...) instead.