- Home /
 
Button.onClick.AddListener inconsistent
Hi, everyone! I'm trying to onClick.AddListener to a bunch of buttons on a canvas on my scene. The scene is a Menu scene to a multiplayer game. Everything works fine the first time, but when this scene reloads, and I set up the buttons from the onLevelWasLoaded method, sometimes the listeners get added to the button, sometimes they don't at all. Here's the code:
 Button[] buttons = {
                 homePanel.transform.GetChild(0).GetComponent<Button>(),
                 homePanel.transform.GetChild(1).GetComponent<Button>()
             };
             foreach (Button button in buttons){
                 Debug.Log($"Fetched button name = {button.gameObject.name}");
                 button.onClick.RemoveAllListeners();
             }
             buttons[0].onClick.AddListener(EnableLANScreen);
             buttons[1].onClick.AddListener(EnableInternetScreen);
 
               What might be going wrong?
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Passing through a GameObject/Function to a button's OnClick 1 Answer
The button works only after repeated mouse hover. 0 Answers
Creating working UI Button from Script? 1 Answer
Button only works once 1 Answer
Pause button not getting clicked 0 Answers