- Home /
Multiple Materials Same Prefab
I have bought a character (.fbx). I have got one character prefab and 1 material.
I have got 10 textures. Now I want to know a way so that I can make 10 characters with different the textures. (if i change texture on the material it changes texture of all characters)
Answer by Dreamora · Apr 07, 2013 at 07:32 PM
There are two ways:
In the editor: Dublicate the material in the project window. Change the texture on this dublicate and assign it to the mesh which shall use this material. Repeat this for the other characters. After that you might want to create 10 new proper prefabs from them so you can attach further things (your original prefab is one linked to the mesh and not suitable for this purpose)
In code, you can use gameObject.renderer.material.mainTexture = someTexture. If you do that, Unity will automatically clone the material before you assign the texture and it yields the same result as the one above. (if you wanted to replace the texture on all instances of the object, you would use sharedMaterial instead)
Aah that was not the issue. It is a character made on some 3d software so unity automatically created a material. There is no material actually assigned to the gameObject.
I solved it though. I changed the name unity made materials. So for every new important I got a new material so I assigned separate textures. Thanks for replying anyway,
Thats correct, unity will autocreate a material. But that does not impact the above approach luckily.
Simply drag the mesh prefab into the scene and you can replace the material on the Renderer component of it. Also the auto generated material is just a material, nothing special or hidden. Normally its actually just a diffuse material. After that, drag the object from the scene into your project window and it will create a new prefab for this specific configuration
But great to hear that you could resolve it.
Your answer
Follow this Question
Related Questions
Runtime change texture 3 Answers
Changing GameObject texture? 4 Answers
How to create a GUI button to change a character's texture in real-time? 2 Answers
Character Material Layers 0 Answers
randomly changing texture of material 2 Answers