When adding a model to the scene multiple times, changing the material on one of them causes all models to change to the same material. Have you seen this? Is there a work around?
Currently the material->mesh instance mapping is stored in the asset. So if you modify the material or which material is assigned in the editor it will effect all instances of the model.
There are two work arounds:
- Upload the same model multiple times and assign different materials.
- Use a script to change the material on the mesh instance at runtime.
Maybe I’m doing something wrong. Option 1 doesn’t work for me. I’ve followed the instructions I’ve found in Answers, that is, select it, frame it, then select it again, and change the material.
Yes, I can frame the model, and I can delete the material assigned to the model. But once I delete the material it deletes it off all the other models too.
Regarding option 1: this means upload the same model but with a different name multiple times - if you upload the same model with the same name then the original model will just be overwritten. So if your model is named model_1 then name it model_2 and upload it, then model_3 and upload it etc.
Re-uploading the same model is definitely not ideal though as it will make your game bigger and waste your disk space so I suggest changing the model material at runtime by script instead of re-uploading the same model multiple times.
@steve_wk, Another solution is to create multiple material variations in the Editor and have a script that can map an array of materials to the mesh instances on the model (probably using JSON schema attributes).
Assuming that the mesh instance order doesn’t change when updating the model, this would work and be pretty quick to do.
If it does change, then you would have to map the material to mesh instance name. A bit more fiddly but doable.
The above is assuming that you want to change at runtime.
If it’s just in the Editor, you can override the default mapping with new materials on the model component