Fade Out an UI image in gameview from EditorWindow

Hello,

I don’t know if it’s a bugg, I din’t find answer on the web.

I try to Fade Out an UI image in gameview from EditorWindow with the Update method (of EditorWindow). That work ! but not really…

I know that IEnumerator/WaitForSecond methods don’t work in EditorWindow. So I use the Update method to make the job.
That work perfectly with Image.RectTransform.anchordePosition, every times UpdateMethod is called, the position of the Image in Gameview move correctly but not with Image.color.a.
Every times UpdateMethod is called I can see in inspector Alpha’s color is correctly decrement but visually in gameview that stay opaque. (In gameView that turn correctly gradually transparent only if I click continually on the EditorWindow)

Here is my script :

 public class test : EditorWindow {

Image imageToFadeOut; // UI image to modify
Color colorTemp; // Color for change the alpha
bool Fadout = false; // bool to launch the alpha decrement in Update method

void OnGUI()
{
    imageToFadeOut = (Image)EditorGUILayout.ObjectField(imageToFadeOut, typeof(Image)); //Drag & drop Image here

    if (GUILayout.Button("FadeOut")) //if I push this button from my EditorWindow
    {
        if (imageToFadeOut != null) //if image is not null
        {
            colorTemp = imageToFadeOut.color; //Get the current color
            Fadout = true; //launch the method
        }            
    }
  }

 void Update () //methode called 100 time per second 
 {
	if (Fadout)
    {
        colorTemp.a -= .002f; //decrement the alpha of the color
        imageToFadeOut.color = colorTemp; // apply the color with alpha modified to the color of UI image

        if (colorTemp.a <= 0) //if alpha of the color equal 0 , stop to decrement
            Fadout = false;
    }
  }

Someone know how I can fix my problem please ? Or just if it’s possible ?

103782-problem.png

You can set the Object as Dirty and that will update it in the scene view.

void Update () 
	{
		if (Fadout) {
			/..
			EditorUtility.SetDirty (imageToFadeOut);
		}
	}

Perfect ! It work so much now. thank you!!

I’m not sure to understand what “SetDirty” mean… and why the dirty object is updated in gameview. Could you tell me more about this method please ? (I read unity doc but there is not really explication ?)