Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Since Upgrading Project 2018.3 To 2019.1.0f1 My Images On Canvas Are All Colorless (dynamically)

Discussion in '2019.1 Beta' started by Firlefanz73, Apr 14, 2019.

  1. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello,

    in my gui everything based on sprites is white now. This worked perfect before.
    Why is it White instead of orange? A bug or something I Need to Change, Maybe a material on the Image or some property of the sprite?

    upload_2019-4-14_19-32-46.png

    Thanks a lot :)
     
  2. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Setting Color on Image dynamically in Code with testImage.color = mycolor does not do any Change anymore. Did before.
    But material.Color still seems to work on an Image. But it seems other Images then get the Color, too...
     
    Last edited: Apr 15, 2019
  3. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    PS: To make a better understanding:
    There was no material in my Image first, and the source is a sprite in this case. The material was set later for testing purposes, but that did not help.

    I have set my Colors dynmically just like this:

    testImage.color = mycolor
    That worked before, but does not work anymore, it stays White like in the screen above.

    Setting the Images defaultmaterial or material Color changed every UI element Color, and it stayed that way, I had to close Unity and reopen it to have my ui in it's Default Colors again.

    If found no Workaround to set my Images Color dynamically, how do I?

    Thanks!
     
  4. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,135
    Could you please submit a bug report with a minimal reproduction project for this issue?
     
  5. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I made a new Project with Unity 2019. I copied my texture into and set the properties to sprite (it is an atlas with many).
    I added an Image to the canvas in the new Project.
    I made sure the Image properties in the Scene and the file properties of the Image file are the same.

    In the new Project it works perfect, and in the old it does not.
    Maybe has something to do with the update? I tried to reimport the file in the old Project, no Change...

    In the inspector the Color is fine! Only in game view it is not...
     
  6. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    When I set this on the Image after changing the sprite or the Color, it works perfect.

    leftCursor.DisableSpriteOptimizations();

    In the previous Unity Version this was not necessary. Just to let you know, perhaps it helps somebody.
    In the new Project I created for testing purposes, it was okay without doing so.
    Solved for me.
     
    LeonhardP likes this.
  7. starform-joshrosen

    starform-joshrosen

    Joined:
    Aug 29, 2018
    Posts:
    8
    We are having the exact same problem. Some of our Images aren't showing color changes made by scripts, unless DisableSpriteOptimizations is called on the Image.

    I stepped into the Unity UI code through the debugger and can partially see the bug occurring, but I'm not sure what causes it initially.

    Using the color setter does call SetVerticesDirty, which later results in the Image getting its UpdateGeometry method called. In UpdateGeometry, the Image's m_UseCache field is true, and so it only updates the m_CachedUvs and m_CachedMesh.uv fields, but doesn't update the color data which is stored in the vertices.

    If m_UseCache was false instead, then it would call base.UpdateGeometry(), which calls DoMeshGeneration, which calls OnPopulateMesh, which finally puts the color data into the vertices.

    Calling DisableSpriteOptimizations sets m_UseCache to false, but it also sets m_SkipLayoutUpdate and m_SkipMaterialUpdate to false, so I'm not sure if this will cause us to miss out on other optimizations that aren't causing issues.

    In the below screenshot, note how the selected green triangle has a red color in the inspector.
    Screen Shot 2019-04-20 at 11.47.46 PM.png
    Screen Shot 2019-04-21 at 12.06.31 AM.png
     
    Last edited: Apr 21, 2019
  8. starform-joshrosen

    starform-joshrosen

    Joined:
    Aug 29, 2018
    Posts:
    8
    Also, I wanted to not that DisableSpriteOptimizations is in fact a new API in 2019.1, it did not exist in 2018.3.
    https://docs.unity3d.com/2019.1/Doc...ence/UI.Image.DisableSpriteOptimizations.html

    "Disables all automatic sprite optimizations.
    The sprite change optimizations include skipping layout update, skipping material updating and using a cached mesh for rendering and only updating UV's. The next time the Image needs updated it will default back to normal behaviour ignoring any optimizations."

    And as of now, this brief documentation entry and this forum post are the only references I can find to this function on Google. It would be great to get a blog post from Unity about what these optimizations are exactly and how to take advantage of them.
     
  9. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Hey,

    So the cached sprite mesh optimization will be removed here shortly. We missed a few edge cases that are causing issues so for at least the time being we will back them out till we can think of a better solution. Yes calling the DisableSpriteOptimizations works but in terms of animation it does not so we need to figure out that case.

    The other 2 optimizations (not dirtying layout/ dirtying the material) will stay in place as the logic there seems solid. Will get the fix out asap.
     
    Immu and LeonhardP like this.
  10. Immu

    Immu

    Joined:
    Jun 18, 2013
    Posts:
    240
  11. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Yes it should be fine the issues you are talking about are caused by the mesh caching. the other 2 optimizations do more logical checks and have fewer edge cases. That being said without a repo i can't say 100% but every bug i have gotten about the sprite being busted has been fixed with the cache removal.
     
  12. komodor

    komodor

    Joined:
    Jan 2, 2013
    Posts:
    36
    i had that issue on 2 groups of things in 2019.1.0f2, after update to 2019.1.1f1 one of the groups started to work as supposed (all the alpha tweening is displaying correctly), but the other usage where i tween alpha to 0, then change the sprite and tween back to 1 isn't working like before (if I change it from simple to let's say filled it displays but not with simple)

    so i was looking and i found 2 differencies - the not displaying sprite was rect mesh and not in atlas ... so i checked mesh and still no success but when i atlased the sprite it started to display

    i guess the bug was half fixed in update to 2019.1.1f1 but since it works only with atlased sprites (the particular image isn't POT)
     
  13. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    The fix hasn't landed in 19.1 yet, There were issues around getting it backported and differences in the code base that i needed to resolve. Hopefully will land soon.