Search Unity

4.6 Bug with Filled Image

Discussion in 'Immediate Mode GUI (IMGUI)' started by Xylph, Oct 3, 2014.

  1. Xylph

    Xylph

    Joined:
    Dec 11, 2013
    Posts:
    30
    I have a Filled Image used to represent skill cooldown. For the first time, the filled image works properly. After that, the image is completely gone even though the Fill Amount is still being updated (as seen in the inspector)

    Weird thing, whenever I click on anything in the Image inspector, the image shows up and works properly again (just for one run).
     
    Last edited: Oct 3, 2014
  2. Xylph

    Xylph

    Joined:
    Dec 11, 2013
    Posts:
    30
    Here's a quick fix for those who have the same problem. I'm not sure what's happening under the hood but whenever you set Image.fillAmount to 0, the image never gets rendered.

    If there's a less-hacky/proper way to do this, please tell me.

    EDIT: Setting the fillAmount value to near zero also keeps the image from rendering. I make sure that the value is at least 0.001f to make it work.


    Code (CSharp):
    1.  
    2. public class TestFilledImage : MonoBehaviour {
    3.  
    4.     private Image image;
    5.     private float fillAmount;
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.         image = GetComponent<Image>();
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.         if (fillAmount >= 1.0f) fillAmount = 0;
    15.         else fillAmount += Time.deltaTime * 0.2f;
    16.  
    17.         image.fillAmount = Mathf.Max(fillAmount, 0.001f);
    18.     }
    19. }
    20.  
     
    Last edited: Oct 6, 2014