- Home /
Question by
thelonelypanda · Jan 30, 2021 at 06:44 AM ·
c#prefabsmaterials
How to change a prefab's color before instantiating (with code)
I've googled and found a multitude of forums discussing this topic but nothing that satisfied what I need to do.
My situation: My game has a store where you can unlock aesthetic changes to the objects that are procedurally generated in the scene. These aesthetic changes are stored as materials. How can I use C# to change the non-instantiated prefab's material?
Comment
Answer by Llama_w_2Ls · Jan 30, 2021 at 10:12 AM
I don't think you are able to change or delete anything regarding a prefab in Unity, due to data loss, or it is highly recommended against. I might be wrong. However, you could try creating a copy of the prefab with a different color, and adding it to your prefabs folder. Try having a look at PrefabUtility. See Doc Here
Your answer
![](https://koobas.hobune.stream/wayback/20220613024231im_/https://answers.unity.com/themes/thub/images/avi.jpg)