Make sprite transparent without changing material?

I have two sprites sharing the same material. In my game, one of these sprites is not interactable at times, so I would like to lower the transparency to indicate that. I know I could just create a separate material for each sprite, but at some point I will have many more sprites than just two, and creating potentially hundreds of materials for this purpose seems inefficient.

Is there a way for an object to inherit its parents transparency or something? Or maybe a way to apply a second material to the sprite which would make it transparent?

Thanks!

You can just reduce the alpha of the color of sprite renderer. The manual even directly states “To change a Sprite’s opacity, change the value of its Color property’s Alpha (A) channel.”
Additionally I’d recommend darkening the actual color as well, it is up to you.
You can do the same things for a UI image component

Not sure why you need this; currently there is no event/callback for when a sprite renderer’s color changes, so you’d either have to bite the bullet and check for parent’s sprite renderer’s color change every frame(or every .1 seconds etc.) or make sure you notify the children’s relevant scripts when you change parent’s color in code etc. You could probably write an extension method to streamline this(if your children dont change, it would be faster to cache their scripts/components that need a notification/callback when you change the parent’s color)

Option2 for indicating a sprite is

Just put another white square sprite on top of not interactable sprite and set it’s sprite renderer color to gray with .5 alpha. I wouldn’t recommend this unless you can scale this dark sprite over multiple not interactable sprites

1 Like