Search Unity

Bug When a Scene first loads it takes 2 presses of a button to make a panel visible

Discussion in 'UI Toolkit' started by MancinoTech, Jan 27, 2023.

  1. MancinoTech

    MancinoTech

    Joined:
    Jan 14, 2023
    Posts:
    1
    In my LevelScene I have 2 UI buttons, one for reset and one for home. I have 3 panels, 2 for the reset and home confirmation and a win panel. When I load my LevelScene for the first time the buttons take 2 presses of home or reset to open a confirmation panel, but only a single press on all subsequent presses. I thought the onClick() wasn't happening because of something in my input system but when I added logging to my TogglePanel() function it seems to be called on the first click yet my panel still doesn't activate. Here is my code and the debug that results. I pressed each of my buttons 3 times during run time.

    Code (CSharp):
    1. private void Start()
    2.     {
    3.      
    4.         if (openPanel != null)
    5.         {
    6.             openPanel.SetActive(true);
    7.             openPanel.SetActive(startsVisible);
    8.         }
    9.     }
    10.     public void Toggle()
    11.     {
    12.         Debug.Log("Toggle Panel");
    13.         if (openPanel != null)
    14.         {
    15.             bool isActive = openPanel.activeSelf;
    16.             Debug.Log(openPanel.gameObject.name + " Panel open = " + isActive);
    17.             openPanel.SetActive(!isActive);
    18.             Debug.Log("Panel open now = " + openPanel.activeInHierarchy);
    19.         }
    20.     }
    Debug Log:
    Code (CSharp):
    1. Toggle Panel
    2. ExitUI Panel open = False
    3. Panel open now = True
    4. Toggle Panel
    5. ExitUI Panel open = False
    6. Panel open now = True
    7. Toggle Panel
    8. ExitUI Panel open = True
    9. Panel open now = False
    10. Toggle Panel
    11. RestartUI Panel open = False
    12. Panel open now = True
    13. Toggle Panel
    14. RestartUI Panel open = False
    15. Panel open now = True
    16. Toggle Panel
    17. RestartUI Panel open = True
    18. Panel open now = False
    Any advice? This script is attached to each button and openPanel is a public variable and each button only has it's own panel referenced. I'm combing through code but I don't believe the panels are referenced elsewhere (is there a way to trace this for sure?). None of the buttons on the panels themselves (applied from the same prefab) have this issue. I also have a level win panel which gets called from my score manager script and that activates when call it the first and only time in a script. I first thought it may be from the new input system because of my touchscreen multi-tap events but the problem persists even if I disable the simulated touchscreen controls in the input debug, not to mention the function seems to be running. Note, the code o
     
    Last edited: Jan 27, 2023