How to modify material property used on multiple meshes without making it unique

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

I have a 2.5D side-view game in which you enter a building and only the room you are in is visible, and every other room is covered with simple CSGBox mesh with black material like this:
enter image description here

Logic is simple, every room has it’s own area with:

func _on_RoomArea_body_entered(body):
	blackFade.visible = false

func _on_RoomArea_body_exited(body):
	blackFade.visible = true

So if I go from Room 4 to Room 1, the logic in Room 4 will turn visible to true for itself, and Room 1 logic will turn visible false for itself.

And it works but it’s not clean since it just pops in and out. I wanted to play FadeIn and FadeOut animation through AnimationPlayer but the problem is: Every CSGBox uses the same material so if I change alpha for one, it changes for all of it. The easy solution is to make unique material for each black panel, but that’s a lot of unique materials, what if there are 100 rooms, that’s 100 unique materials that will change only alpa and the rest stays the same. So is there a way to modify a property (albedo → alpha) for the material without making it unique and have hundreds of duplicates?

:bust_in_silhouette: Reply From: Inces

If You want to animate materials property, which cannot be shared by all instances - there is no other way. You don’t really have to make_unique, You can just set local_to_the_scene property for parent scene in editor to true. I doubt this will cost much of a framerate though, since they will be invisible most of the time. If You really need to optimize this, I guess You could eventually set unique materials only for the rooms player is currently relocating, until they are animated, and than just change all invisible rooms materials to shared one.