Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Button clicked event executes twice

Discussion in 'UI Toolkit' started by Kan15hkSMT, Jul 24, 2020.

  1. Kan15hkSMT

    Kan15hkSMT

    Joined:
    Nov 13, 2019
    Posts:
    37
    I am using the UI Toolkit Version 1.0.0-preview.3 with Unity 2020.1.0b13.

    We have our own implementation of dropdown which uses a button and then toggles a list view panel when the button is clicked.

    Unfortunately when we click on the button the click is executed twice which causes are dropdown to never open (because the initial state is off for the list).

    Here is the code that we are using:

    Code (CSharp):
    1. dropdownButton.clickable.clicked += ToggleDropdown;
    2.  
    3. public void ToggleDropdown()
    4. {
    5.         bool isRevealed = listView.style.display == DisplayStyle.Flex;
    6.         RevealDropdown(!isRevealed);
    7. }
     
  2. Digika

    Digika

    Joined:
    Jan 7, 2018
    Posts:
    225
    Are you applying even hook to each button AND the dropdown itself? I recommened using one top-level even hook and parse the event.target there for all events for that element container.
    Otherwise, taking big leap of assumption, I'm guessing when you click button the event later also being propagated to dropdown which causes it it close? See if adding StopPropagate will help
     
  3. Refeas

    Refeas

    Joined:
    Nov 8, 2016
    Posts:
    192
    Are you sure the event is triggered twice? I had similar issue and it turned out
    style.display
    returned null the first time I checked it. I solved it by using
    resolvedStyle
    instead.

    So, try switching
    Code (CSharp):
    1. bool isRevealed = listView.style.display == DisplayStyle.Flex;
    for
    Code (CSharp):
    1. bool isRevealed = listView.resolvedStyle.display == DisplayStyle.Flex;
     
  4. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    Hey @Kan15hkSMT, we found a bug recently that sounds like what you're describing. If you use the latest Unity 2020.1 (that was just announced) without the UI package you won't have issues, and there should be a new version of the UI package containing the fix coming soon ;)
     
    Kan15hkSMT likes this.
  5. Kan15hkSMT

    Kan15hkSMT

    Joined:
    Nov 13, 2019
    Posts:
    37
    Thank you Julia. Please let us know when the new version of the package is out.
     
  6. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666