I’ve verified that this is an issue in 5.5.0a6 and the issue does not exist in 5.4.2f2. If you have a GameObject with a SpriteRenderer and try to change the color property at runtime in a script, it will change the color of the SpriteRenderer in the Inspector but will not change the color of the sprite itself in the scene, game view or running build.
If you manually change the color through the Inspector, it changes correctly in the scene view and game view. It is very easy to reproduce this, just create a script that changes SpriteRenderer.color in the Update function and attach it to the GameObject that has a SpriteRenderer.
Here is a link to 2 simple projects that illustrate the issue. One for version 5.5.0a6 which DOES contain the issue and the exact same project for version 5.5.2f2 which DOES NOT contain the issue.
Can confirm. I also have this issue. It doesn’'t mater weather you change the color property of the sprite renderer or change the “_Color” property of the material. Neither works.
Today I switched back to beta 5.5 and… tada! suddenly my animated sprite colors worked again
The changing of spriterenderer’s color property does seems to work at first, but then when you change its material or shader to something else that is also based on the default sprite shader at runtime, it does not change the color of the sprite.
I have confirmed this with changing the shader of the sprite’s renderer material to the exact same copy of the default sprite shader and the shader does not receive the vertex color information from the spriterenderer.
However, setting the _Color value of the material does seem to work.
This happens only when you change spriterenderer’s material shader into something else during runtime. Even if the changed shader is actually the same shader as the default sprite shader.
Something odd is happening when spriterenderer’s material’s shader changes… perhaps the spriterenderer is not expecting such changes during runtime?
Has this been fixed? Three years later I’m experiencing the same thing. Setting SpriteRenderer.color = new Color(255,215,215); results in the property being set to r=192, g=162, b=162 in the inspector but no update in the scene.
Have just realised there was no bug (in my case anyway). I was attempting to alter the .material.mainTexture property of my , when in fact I should have been setting it’s .sprite property to a newly created sprite.
The first answer on this post contains the solution:
Texture2D texture = new Texture2D(128, 128);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, 128, 128), Vector2.zero);
GetComponent<SpriteRenderer>().sprite = sprite;
texture.SetPixels() #do something here
texture.Apply()
Thanks all, hope this can close my report @Ted_Wikman
Great that you found a fix to your issue, and thanks for posting it here.
You can add this information to the bug ticket as well to let the Unity QAs know about your solution.
Thanks!