Flickering GUI

Hello,

I have problems with Flickering GUI while selecting text or clicking many times.

I cant describe it so I’ve created an video.

Maybe you’ll need the Camtasia Plugin to view this.

http://download.techsmith.com/tscc/tscc.exe

Is it a Unity bug or my bad?

Thanks for helping

Video:
http://china-store.eu/Unity/Aufnahme-1.html

It’s hard to tell if this is a bug or not from the video. Can you post the script you are using for your GUI?

uff the whole gui code has 250 lines.

Ill post code snippets, if you need the whole script tell me.

if(registrationMenue == true){
				//Registration Popup
				GUILayout.Window(2, Rect(Screen.width/2-76,Screen.height/2-100, 150,200), RegistrationWindow, "Account erstellen");
	}
function RegistrationWindow(windowID : int){
		GUILayout.BeginVertical();
		//Username
		GUILayout.Box("Username");
		username = GUILayout.TextField(username, 15);
		//Password
		GUILayout.Box("Password");
		password = GUILayout.PasswordField(password,"*"[0], 15);
		//Email
		GUILayout.Box("Email");
		email = GUILayout.TextField(email, 30);
		if(GUILayout.Button("Registrieren")){
		networkView.RPC("CreateAccount", RPCMode.Server, username, password, email);
		}
		//Cancel Registration
		if(GUILayout.Button("Abbrechen")){
		username = "";
		password = "";
		email = "";
		
		ShowMainMenueMultiplayer();}
		GUILayout.EndVertical();
}

Thanks for helping

I think you will need to post the whole script, actually. I can’t see anything wrong in particular with the code you’ve posted but I’m guessing that the problem is a control that is added conditionally and for some reason the condition changes each frame.

Okay here is the whole script:

#pragma strict
//Variablen

private var username : String = "";								//Saves the username of the user
private var password : String = "";								//Saves the password of the user
private var serverIP : String = "";									//ServerIP where we will connect to
private var serverPassword : String = "";
private var email : String ="";										//Whats your mail?
private var loginStatus : String = "Kontaktiere Server";		//Display Current Login Status
private var mainMenue : boolean = true;						//Show MainMenue?
private var mainMenueMultiplayer : boolean = false;		//Show MainMenueMultiplayer?
private var loginMenue : boolean = false;						//Show LoginPopup?
private var optionMenue : boolean = false;					//Show Options?
private var registrationMenue : boolean = false;				//Show Registraion?
private var mainMenueServerIP : boolean = false;			//Show Server IP Popup
private var FullScreen : boolean = Screen.fullScreen;		//Checking if FullScreen is using
private var connectionStatus : String = "Status";				//Connection Status while connecting
private var registrationUnsucessfullError : String = "";
private var registrationUnsucessfullMenue : boolean = false;
private var registrationSucessfull : boolean = false;
private var registrationSucessfullMenue : boolean = false;

function OnGUI(){
	if(mainMenue == true){
		GUILayout.BeginArea(Rect(Screen.width/2-75,Screen.height/2-100, 150,200));
			GUILayout.BeginVertical();
				//Start Singleplayer
				if(GUILayout.Button("Einzelspieler")){Debug.Log("Singleplayer started");}
				//Show Multiplayer Menue
				if(GUILayout.Button("Mehrspieler")){ShowMainMenueServerIp();}
				//Show Options
				if(GUILayout.Button("Optionen")){ShowMainMenueOptions();}
				//Quit Button
				if(GUILayout.Button("Beenden")){Application.Quit();}
			GUILayout.EndVertical();
		GUILayout.EndArea();
	}
	
	else if (mainMenueServerIP == true){
		GUILayout.BeginArea(Rect(Screen.width/2-75,Screen.height/2-100, 150,200));
			GUILayout.BeginVertical();
				//Connection Status
				GUILayout.Box(connectionStatus);
				//ServerIp
				GUILayout.Box("Server IP");
				serverIP = GUILayout.TextField(serverIP, 15);
				GUILayout.Box("Passwort");
				serverPassword = GUILayout.PasswordField(serverPassword,"*"[0], 15);
				//Connect!
				if(GUILayout.Button("Verbinden")){connectionStatus = "Verbinde...";
					Network.useNat = false;
					Network.Connect(serverIP, 25000, serverPassword);}
				if(GUILayout.Button("Zurück")){
					ShowMainMenue();
					}
				
			GUILayout.EndVertical();
		GUILayout.EndArea();
	}
	
	else if(mainMenueMultiplayer == true){
		GUILayout.BeginArea(Rect(Screen.width/2-75,Screen.height/2-125, 150, 250));
			GUILayout.BeginVertical();
				//Username
				GUILayout.Box("Username");
				username = GUILayout.TextField(username, 15);
				//Password
				GUILayout.Box("Password");
				password = GUILayout.PasswordField(password,"*"[0], 15);
				//Login Button
				if(GUILayout.Button("Login")){StartLogin();}
				//Registration Button
				if(GUILayout.Button("Account erstellen")){StartRegistration();}
				//BackToMainMenue
				if(GUILayout.Button("Zurück")){Network.Disconnect();
				ShowMainMenueServerIp();}
				//Quit Button
				if(GUILayout.Button("Abbrechen")){Network.Disconnect();
				ShowMainMenue();}
			GUILayout.EndVertical();
		GUILayout.EndArea();
	}
	else if(loginMenue == true){
				//Login Popup
				GUILayout.Window(0, Rect(Screen.width/2-75,Screen.height/2-20, 150, 100) , LoginWindow, "Loginversuch");
	}
	else if(optionMenue == true){
				//Option Popup
				GUILayout.Window(1, Rect(Screen.width/2-75,Screen.height/2-100, 150,200), OptionWindow, "Optionen");
	}
	else if(registrationMenue == true){
				//Registration Popup
				GUILayout.Window(2, Rect(Screen.width/2-76,Screen.height/2-100, 150,200), RegistrationWindow, "Account erstellen");
	}
	else if(registrationUnsucessfullMenue == true){
				GUILayout.Window(3, Rect(Screen.width/2-76, Screen.height/2-100, 150,200), RegistrationUnsucessfullWindow, "Fehler");
	}
	else if(registrationSucessfullMenue == true){
				GUILayout.Window(4, Rect(Screen.width/2-76, Screen.height/2-100,150,200), RegistrationSucessfullWindow, "Erfolgreich");
	}
	else{Debug.Log("Error cant find any Popup Window");
	}
}

function Update(){
		//Check if Enter or KeyPadEnter is pressed to start/cancel login
		if (Input.GetKeyDown (KeyCode.Return) || Input.GetKeyDown (KeyCode.KeypadEnter)){
			if(loginMenue == true){CancelLogin();}
			else if(mainMenueMultiplayer == true){StartLogin();}
		}
}

function LoginWindow(windowID : int){
		//Login Window Popup while checking account/connection
		GUILayout.BeginVertical();
		GUILayout.Box(loginStatus);
		if (GUILayout.Button ("Abbrechen")){CancelLogin();}
		GUILayout.EndVertical();
}

function OptionWindow(windowID : int){
		GUILayout.BeginVertical();
		FullScreen = GUILayout.Toggle(FullScreen, "Vollbild");
		if (GUILayout.Button ("Übernehmen")){Screen.fullScreen = FullScreen;}
		if (GUILayout.Button ("Schließen")){CloseOptions();}
		GUILayout.EndVertical();
}

function RegistrationWindow(windowID : int){
		GUILayout.BeginVertical();
		//Username
		GUILayout.Box("Username");
		username = GUILayout.TextField(username, 15);
		//Password
		GUILayout.Box("Password");
		password = GUILayout.PasswordField(password,"*"[0], 15);
		//Email
		GUILayout.Box("Email");
		email = GUILayout.TextField(email, 30);
		if(GUILayout.Button("Registrieren")){
		networkView.RPC("CreateAccount", RPCMode.Server, username, password, email);
		}
		//Cancel Registration
		if(GUILayout.Button("Abbrechen")){
		username = "";
		password = "";
		email = "";
		
		ShowMainMenueMultiplayer();}
		GUILayout.EndVertical();
}
function ShowMainMenueMultiplayer(){
		mainMenueServerIP = false;
		mainMenueMultiplayer = true;
		registrationMenue = false;
		mainMenue = false;
}
function ShowMainMenueServerIp(){
		mainMenue = false;
		mainMenueServerIP = true;
		}
function ShowMainMenue(){
		//Shows the mainMenue
		mainMenue = true;
		mainMenueMultiplayer = false;
}
function ShowMainMenueOptions(){
		mainMenue = false;
		optionMenue = true;
}
function StartLogin(){
		//Opens Login Popup, Close Main Menue Window
		mainMenueMultiplayer = false;
		loginMenue = true;
		Debug.Log("Starte Login");
}

function StartRegistration(){
		mainMenueMultiplayer = false;
		registrationMenue = true;
		registrationUnsucessfullMenue = false;
		Debug.Log("Starte Registration");
}

function RegistrationSucessfull(){
	Debug.Log("erfolgreich");
	registrationMenue = false;
	registrationSucessfullMenue = true;

}

function RegistrationSucessfullWindow(windowID : int){
		GUILayout.BeginVertical();
		GUILayout.Box("Registration Erfolgreich");
		if (GUILayout.Button ("Zurück")){ShowMainMenueMultiplayer();}
		GUILayout.EndVertical();
}
function RegistrationUnsucessfullWindow(windowID : int){
		GUILayout.BeginVertical();
		GUILayout.Box(registrationUnsucessfullError);
		if (GUILayout.Button ("Zurück")){StartRegistration();}
		GUILayout.EndVertical();
}

function RegistrationUnsucessfull(status : int){
		registrationMenue = false;
		registrationUnsucessfullMenue = true;
		if(status == 0){
			registrationUnsucessfullError = "Es ist ein unbekannter Serverfehler aufgetreten";
		}
		if(status == 2){
			registrationUnsucessfullError = "Username existiert bereits";
		}
}

function CancelLogin(){
		//Cancel Login, show MainMenue Close Login popup
		mainMenueMultiplayer = true;
		loginMenue = false;
		Debug.Log("Loginversuch abgebrochen");
}

function CloseOptions(){
		//Close Options
		mainMenue = true;
		optionMenue = false;
}

function OnFailedToConnect(error: NetworkConnectionError)
{
	connectionStatus = error.ToString();
}

function OnConnectedToServer() {connectionStatus = "Status";
ShowMainMenueMultiplayer();}

/*
@RPC
function CreateAccount (username : String, password : String, email : String) {}

@RPC
function CreationStatus (status : int){
	//Successfull
	if(status == 1){
		RegistrationSucessfull();
		}
}
*/

I think this is probably a display bug - I wanted to check there was nothing in your code that was calling a GUI function conditionally. Please can you file a report for this (menu: Help > Report A Problem).

Thanks, I’ve reported this error.

Got the same flickering problem (Windows XP SP3).

To reproduce it:

  • Create a GUI button (I am using GUILayout.Button)
  • Click on that button and HOLD down the mouse button
  • Now drag the mouse around

While dragging the mouse with the button held down, the GUI flickers.

EDIT:
The GUI also flickers when pressing Backspace within a textfield. If the Backspace key is held down, the GUI completely disappears while holding the key.

I agree MauMau. Same problem here.

If I additionally call OnGUI() from within the Update()-Function, the flickering does NOT appear (anyway, this results in an error message “ArgumentException: You can only call GUI functions from inside OnGUI.”):

function Update()
   {
   ...your code...
   
   OnGUI();
   }


function OnGUI()
   {
   ...GUI code...
   }

However, this eliminates the mouse-down flickering.

Thanks MauMau… But I think this will double the CPU usage. Because OnGUI is called by itself and by Update function!

But its a nice hotfix.

Thanks

I don’t know if this is related to my own code or if it is not allowed to call OnGUI from the Update function, but using my method described above, I get the following error message:

“ArgumentException: You can only call GUI functions from inside OnGUI.”

Its not your bad. It is normal that OnGUI functions can only be called in OnGUI :slight_smile:

This is because Unity checks to make sure that all GUI functions are triggered by Unity rather than just any old function named OnGUI().

GUIUtility.CheckOnGUI() is used internally by Unity to ensure that the GUI has been properly initialized and is in a correct state, and checks an internal flag called s_IsInOnGUI to know whether the GUI state is good.

You’ll have to come up with another workaround, calling OnGUI from your own code doesn’t work.

I was declaring the Rect(x,y,w,h) for a GUI window in the function OnGUI(). Only declare Rect for windows outside of OnGUI(). I moved the Rect to Start() and it worked fine.

That fixed my flicker.

This also happens for me, but ONLY if the TextField is inside a GUILayout.Window that doesn’t fit in the Rect that is passed to GUILayout.Window().

If I create my window like this I get flickering if the content in the window is more than 100 pixels tall:

 GUILayout.Window(0, Rect(0, 0, 100, 100), windowFunction, "Window Title");

If I change the above to have a bigger Rect, the flickering goes away:

 GUILayout.Window(0, Rect(0, 0, 999, 999), windowFunction, "Window Title");

Rect win_rect = new Rect(0,0,100,100)

void OnGUI()
{
win_rect = GUILayout.Window(0, win_rect, createWindow, “”);
}

This should solve the flickering problem. Remember that at every loop the win_rect get fed to the Window method. So if u hard-code the Rect option. The window will reset its size to the hard-coded value and then adjust itself to the content’s size, causing the flicker.

I don’t know if it a bug…
But if I implement a tooltip like this (attaching script to object with collider):

function OnMouseEnter(){
DrawMe = true;
}

function OnMouseExit(){
DrawMe = false;
}

function OnGUI(){
if(DrawMe)
 GUI.Box(Rect(20,20,200,200),"text here");
}

and mouse is simultaneously over that box and collider, box begins to flicker

any ideas how to bypass that? Do I have to Raycast instead of OnMouseEnter/Exit?