Editing a particular prefab's material

Hy, noob here. I have made an animation with shader graph in which the enemies disolve. Then I created a script using C# that makes the enemie start disolving if it hits a player bullet. The problem is that to make the enemie disolve I edit a property of the material, which is the same for all the enemies. I cant create a material for each enemie as they are all prefabs that are instantiated. Is there a way to create a material for each prefab when it spawns?

Renderers in Unity have two Material properties:

  • sharedMaterial
  • material

If you want to make a change that affects all objects that use the same material, you can make a change to sharedMaterial. If you want to just affect one object, use the normal “material” property.

See Unity - Scripting API: Renderer.material