Editing shaders in an instance

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tritun

I have a shader that outlines a sprite a color, and in the script of the scene I change the color using sprite.material.set_shader_param()… but this changes the color of all instances of the scene. How can i make it change only that one instance of the sprite?

:bust_in_silhouette: Reply From: Zylann

Resources are shared by default so that’s why modifying one also modifies all the others: they all have the same material on them.

If you want to have individual modification on an instance, you should make it unique first. You can do this by code, just once (no need to do it every frame):

sprite.material = sprite.material.duplicate()

If you need all your sprite instances to be individual too, you can make the resource local to scene in the editor: go to the scene in which your sprite is located, click on your sprite, go to the material, and check local to scene. This way every instance of the scene will have unique material.