- Home /
How to change the texture of a prefab
I am new to Unity. very new. I just downloaded Unity and I have a sample package loaded. The game has a number of prefabs, and I want to change the texture of one of them. For example, the game has an object that appears in various scenes - let's say a box. The box is a woodgrain texture, but I want it to be a steel box. I can see the texture png file for the prefab. I can see the prefab file and meta file.
What do I need to do to just change the texture of that prefab so that every time an object instantiated from the prefab appears, it appears with the new texture?
Please consider spending time in the Learn area of the website prior to asking questions. Lots of beginner's information can be found there with ease.
You can drag the material you want onto the object in the scene, you can then drag the newly textured object(from the hierarchy window) onto the original prefab.
If you only have textures then this will still work but it will give it a std diffuse shader, which you will probably want to change.
Or you can look at the texture file in the material on the prefab, you can then click on it and pick one from the list that appears.
There are so many ways to do this :D
Look up shaders and materials and do a little bit of searching, reading and learning like Sunny says. This is very basic stuff.
I'm not all that new to unity and I still run into problems with this prefab material stuff. Its poorly engineered and even a beginner should not get lost in the process. It should be as simple as editing materials to desired result > pushing an update prefab with material button.... done. end of story. Having a wonderful time trying to accomplish what should be a very straight forward task right now, and its drivin g me mad.
Answer by fddefdef · Nov 06, 2014 at 11:10 AM
Hi r.daneel,
to do what you want you just have to change the material of the prefab from its renderer component (in most cases the mesh renderer component). Once you changed it, all the game objects you'll instanstiate from that prefab will have that material (and the texture attached to that material).
Thanks for answering. I must be missing something. I navigate to Assets->Prefabs in the Project view and I see the Prefab I want to change. I drag it into the Scene panel, select it, and it's attributes appear in the Inspector. I can see the $$anonymous$$esh Renderer, but that's where I get lots. What I want to do is replace the .png file that is being used as the texture to a different .png file, and therefore a new texture. How do I do that?
Answer by mohit.parihar · Nov 08, 2014 at 06:15 AM
hi,
Texture2D tempTexture = (Texture2D)Resources.Load("Image_name")as Texture2D;
obj.renderer.material.mainTexture=tempTexture;
obj is your game object.
You might want to re-read the question a bit, good answer just not the answer to the question.
Your answer

Follow this Question
Related Questions
Set Graphics Emulation to No Emulation as Default? 2 Answers
UI Elements keep loosing graphic properties, textures aren't visible or outlines only 0 Answers
Unity Editor in extremely low graphics quality 1 Answer
Colldier wireframe and navmesh overlay not showing. 0 Answers
Allow shaders with 'time' variable to update in editor 1 Answer