How to change alpha for specific object without editing color of material
Hi! I'm trying to change the alpha of my sprites, but when I try to use the method described in Sprite Template:
// Properties:
//@input Component.SpriteVisual mySpriteVisual
// Sets the alpha of the sprite visual to 0.5
script.mySpriteVisual.getMaterial(0).getPass(0).baseColor = new vec4(1, 1, 1, 0.5);
it changes alpha for all my sprites (I use multiple duplicates of the same sprite). When I change alpha in Inspector - it changes the alpha of this specific sprite only. How to do that? If it works in Inspector - there must be some way to make the same thing in script, right?
Hi Markus,
Are you using a custom Material on these sprites? The script you pasted will affect any SpriteVisual component sharing that Material.
The slider you see in the Inspector is controlling the same property in the same way - by editing the baseColor property of the SpriteVisual's material:
If you want to see only a specific SpriteVisual change in alpha without affecting others, you can give it a unique Material.
Let me know if you have any questions about how to set that up.
Thanks!
Peter