- Home /
Find and replace material in Scene in editor in C#
I have an FBX model of a theatre I pulled in to Unity. I want to replace the materials used by the seat fabric, but there are hundreds of child renderers I have to go to, to swap them out manually.
I wrote a script to change the material, which does it like this:
[finding loop] var materials = renderer.sharedMaterials; materials[i] = replacer.ReplacementMaterial; renderer.sharedMaterials = materials;
The problem is that when it comes out, it is holding a reference to an instance of the replacement material, not the material itself. If I click on the material in the renderer, it doesn't highlight the source material.
How can I change the material from an editor script when not playing.
Thanks.
Well, what does "Replacement$$anonymous$$aterial" reference? If it's not your desired target material asset of course it doesn't work. There is not enough information in your question to say anything helpful. Apart from that do you use the Undo class to register the changes to the Undo system which will also trigger the serialization system to recognise the changes, Again, just not enough information.
Answer by dan_wipf · Apr 13, 2019 at 05:42 PM
the easier way’s be just editing the materials texture and this’d affect all materials used in your seat
The original material is part of an fbx. I can't edit the materials on the original. I have to replace them.
well you can. if you asign a material to the fbx first
https://docs.unity3d.com/$$anonymous$$anual/FBXImporter-$$anonymous$$aterials.html
Your answer
![](https://koobas.hobune.stream/wayback/20220612195418im_/https://answers.unity.com/themes/thub/images/avi.jpg)