Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

UI Image when Sprite is None

Discussion in 'UGUI & TextMesh Pro' started by mog-mog-mog, Sep 14, 2014.

  1. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    In UI image object, when source image is None. It renders a white sprite.

    UI Image multiply Sprite=None with Color(defaults to White with full opacity) and show White Image even when sprite is not assigned. This is not the same behaviour as in 2d Sprites.

    Is it the desired behaviour in 4.6 or a bug?
    If it is desired behaviour, what's the best way to suppress it?
     
  2. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    image.enabled = false
    image.gameObject.SetActive(false)
     
  3. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    Wondering is this desired behaviour or a bug?
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Its the same behavior like the default (not GUI) shader.
    If you have no image supplied the material will still use the Color.
    I would say its intended.
    You could set the color to transparent and if you assign the sprite you can set the color back to white.
     
  5. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    It is intended behaviour.
     
  6. illustir

    illustir

    Joined:
    Dec 12, 2014
    Posts:
    24
    This is a great way to lose track of the object and never to be able to set a sprite on it again.
     
  7. illustir

    illustir

    Joined:
    Dec 12, 2014
    Posts:
    24
    Thanks, this is the best though weird solution. Transparent being Color.clear (which I just found out).
     
    Gotama likes this.