Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Button is in pressed state when enabled

Discussion in 'UGUI & TextMesh Pro' started by mikeohc, Sep 6, 2021.

  1. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    In the images below, you can see that the progress line method gets called again when the mouse is up, causing a flicker in dialogue.

    1) Dialogue progresses normally until clicked again. Flicker due to button getting called twice. On down and on up.
    ButtonCalled_Flicker.gif
    2) Flicker is gone when I click down without letting go. The call fires again when mouse is up.
    ButtonCalled_Hold.gif
    3) When I interact with any other UI and come back, the problem is gone. Button works normally on first interaction as well. Problem only exist in repeating calls consecutively.
    ButtonCalled_Works.gif

    I can't find the problem no matter where I look in the script. Debug.Log() prints the correct index, so the only lead I found was that the button gets called on mouse up after some testing.

    Any idea why this is happening?
     
  2. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    I found the problem but no solution. So basically EventSystem.current.currentSelectedGameObject still has a reference to the dialogue advance line button. According to Unity UI, onClick gets called on mouse up on the same object. Therefore the advance line gets call again when I initial the dialogue.

    I tried :
    UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(null);


    before initiating the dialogue, but it still doesn't clear the cache.
    Screenshot (331).png

    Edited: even if EventSystem.current.currentSelectedGameObject is null. I still have the same problem of AdvanceLine Button getting called the moment it is enabled when enabled again.
     
    Last edited: Sep 6, 2021
  3. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    Okay, so it appears this is what's happening.

    The button is considered to be in 'pressed' state the moment it is enabled again. I can't figure out why that is. Is it a bug?

    Edited : So the only hacky fix is to disable the AdvanceButton until the 'first mouse up' has completed. Then re-enable the button afterwards. Please tell me there is a better solution...
     
    Last edited: Sep 6, 2021