- Home /
Image sprite loaded from scriptable object ignores color
Problem:
I currently have a UI Image which loads the image sprite from a scriptable object during runtime by setting the Sprite variable of the image, like so:
Image img = GetComponent<Image>();
img.sprite = myScriptableObject.sprite;
However, when I change the alpha of the same image by setting the color,
img.color = new Color(1f,1f,1f,0.5f);
It has no visual effect. You can even see that the color in the inspector is changed, but in both the scene view and game view there is no difference.
Workaround:
1. If I instead set the overrideSprite variable for the image, I get the expected behavior with the color changing properly.
2. When running in the editor, I can change the sprite value of the image to a different sprite and back to the desired one, and the color setting will then be applied.
Unity Version:
2019.1.3f1.
Has anyone else had this issue? Or do I have a misunderstanding of how sprites can be loaded from scriptable objects?