- Home /
Changing the Material of an instance of a prefab only!
Hello there! I am making a 3D game and i have a few floating island prefabs.I drag each time i want to create a new island one of the available prefabs in the hierarchy to add some props on it and then make the new finsihed island a prefab.I've recently noticed that, when i add a new empty floating island and change let's say it's material's color, every single other instance of that prefab including the finished island(the one with the props on) changes material color and that's a huge pain for me since it doesn't allow me to continue with my game.I tried my best to explain this issue and sorry if it's not very understandable!So my question is, can i change the material of an instance of the island prefab without changing every other's material?Sorry if this is a dumb question btw.
This is one of the prefabs for example(the one with the props on it) and imagine the same one without the props,just an empty island prefab.
Answer by Sagi02 · Jun 18, 2016 at 07:12 PM
You just have to create a different material for each different island: when you change a material, all GameObjects with this material will change even if they are not from the same prefab. Remember that a material is passed by reference in the editor and not by value.
So if i delete the current material of a new island i am making,and create a new one and assign it to the island and choose a random color,that color won't apply automatically on the other prefabs or on the base prefab?
yep. Or you can use $$anonymous$$esh.material ins$$anonymous$$d of $$anonymous$$esh.shared$$anonymous$$aterial, it supposedly changes only the current instance of the material (this can't be done in the editor and requires scripting). Re if you want more details how to do this.
Answer by josehzz112 · Jun 19, 2016 at 04:53 AM
This happens because all floating islands share the same material.
You could assing a new material to every new island (not the most efficient solution, but it should work).
I had these issues, and made a system to fix it. The result became an asset in the store. It's called $$anonymous$$ess $$anonymous$$anager in the Asset store. With it you can just select anything and assign new materials on a new prefab it makes on the fly from your template - with a single click. https://www.assetstore.unity3d.com/en/#!/content/85595