Debug.Log - Pressing Button readings.

Hello everyone.

I need desperate help on what’s going on, I’ve been here for like an hour looking at code and still have no idea what’s wrong.

Before I ask my question, here’s the code of a not-so-simple(due to functionality) button layout.

void OnGUI () {


Create DPAD states the obvious.
SetIdleness checks if any button is being pressed.

private void CreateDPAD(){



private void CreateUpButton(){
		_upButton = UpButtonClicked ();
		if (_upButton)
			//Animation code, irrelevant to the problem. :D


private bool UpButtonClicked(){

		//upClicked = true;
		if(GUI.RepeatButton(new Rect(Screen.width - (BUTTON_WIDTH * 2) - 10,Screen.height - (BUTTON_HEIGHT * 3),50,50),"", "Dpad_ArrowU")){
			UpActive = true;
			return true;
		} else {
			UpActive = false;
			return false;

Here’s where my debug statements are.

private void SetIdleness(){

		//Debug.Log ("SettingIdleness");
		if(DownActive || UpActive || LeftActive || RightActive){
			Debug.Log ("A Button is Active!");
		} else if(!DownActive && !UpActive && !LeftActive && !RightActive){
			Debug.Log ("No Button Active");


Now, here’s the wierd part.

This function checks if Im pressing any buttons.
If no button is pressed Debug(“No active Buttons”) else (“Active Button”);
On my dbg WHILE any button is pressed I get this:

  • 1st Line: Active Button…
  • 2nd Line: No activeButtons…

Why is this happening???

Thanks for your time and help, I’ve been looking at code for an hour and I don’t know whats going on…


According to me in your console window, ‘Collapse’ button is pressed, due to which same kind of messages are being grouped together as i show in example image above(highlighted with yellow highlighter)…just disable it and try again. I think your problem should b solved by this. Gud luck :slight_smile:

The problem is that it gets executed several times. You can check it e.g. by also showing Event.current, which will tell you that first the layout is handled and then the actual repainting takes place. Only during the repainting, you are going to get the correct answer.
If you show the value e.g. in Update or any other place than OnGUI, you are going to get the correct result. The problem is that you are using and else for the GUI.RepeatButton. This does not work with an immediate gui solution. This answer was given by @Dantus and it is the solution.