Why do I have to double click on a button the first time?

I’m making an app with Unity in 2D. I have a button on my canvas, but every time you start that scene you have you click on the button twice to fire the OnClick(), but after that you can click the first time, until you restart the scene, then it’s the same thing again. It’s just this scene that is affected.

Thanks for answers!

The first click might just be giving the game view ‘focus’, then the next click is received by the game. Try this: Start the game. Click inside the game view but not on the button itself. Then click the button. Did the button work?

@DoctorTwentyThree & @ghostmode I am having this same problem. i have a panel with a menu panel on, in a layout manager holding 6 buttons. When the button is clicked the user is selecting a menu item i.e. one displays a pop up window which works ok, but another onclick() also changes the image of the button to a pressed image so the user can better visually tell the diff between pressed and not, also for design it looks nicer. But when the scene is loaded the sequence of changing the button image on/off images needs 2 clicks to get working.

I have printed a debug.log statement in the Start() of the scrips that are in use. The 2 scripts Start() do get called b4 the button is clicked. Any thoughts?

Thanks

For people with same problem. Try to move all your UI controlling things affected by button into independent game object.
For example, my pause button was need 2 clicks before I move my call pause menu function into independent game object with new script.
P.S. Sorry for bad english maybe

if your script like this (Pause Script Example).

void Start()
{

}
void Update()
{
    if (GameIsPaused)
        {
            Resume();
        }
        else
        {
            Paused();
        }
   void Resume()
   {
      GameIsPaused = false;
     //your code
    }

    void Resume()
   {
      GameIsPaused = true;
     //your code
    }
}

You should add GameIsPaused =
false
on void Start to avoid
double click. like this

void Start()
{
    GameIsPaused = false;
}

Having the same issue here.

Once per Run I have to click any button inside this one panel twice.

public class PartyMemberManager : MonoBehaviour
{
    public void ButtonHead()
    {
        print("1. Button was pressed");
        transform.parent.GetComponentInChildren<EquipmentManager>(true).ShowHeadGear();
    }

    public void ButtonChest()...
    public void ButtonLegs()...
}

The PartyMemberManager is assigned to a game object.
ButtonGear events are assigned via editor to each button. These are 4 layers deep inside the PartyMemberManager game object.

public class EquipmentManager
{
    public void ShowHeadGear()
    {
        print("2. Sorting head gear...");
        EnableWindow();
    }
    public void EnableWindow()
    {
        print("3. Window is SetActive(true)");
        this.gameObject.SetActive(true);
    }
    public void ShowChestGear()...
}

EquipmentManager is assigned to a gameobject next to PartyMemberManager (sibling).

When ButtonChest function is called the console shows:

  1. Button was pressed
  2. Sorting head gear…
  3. Window is SetActive(true)

Yet the game object is still set to inactive. When clicked again the same messages repeat on the console and the game object is set to active.