Search Unity

I can't select ListView items on UIElements Runtime

Discussion in 'UI Toolkit' started by Curlyone, Apr 17, 2020.

  1. Curlyone

    Curlyone

    Joined:
    Mar 15, 2018
    Posts:
    41
    Hello

    I can't select ListView items, when i register MouseDownEvent on items and debug a log, i can see the log so that means clicking on them actually works but it doesnt select it. When i hover my mouse they change their style but clicking on it doesnt select it. I tried Selection type for single and multiple as well, it doesnt work. I also tried changing Event System to IMGUI events and read input as well but those didnt work either(Read input didnt work at all, in IMGUI events it at least they change their style when i hover my mouse over an item),This was working fine in 2019.3 but i am using 2020.1.0b5 and it doesnt work, weird thing is.. when i hover my mouse over an item and press arrow up/down it starts to select things (in IMGUI events mode). So thats what i am doing right now as workaround but i was wondering if i am doing something wrong.

    One thing i noticed is... i was able to click it once when Unity was loading stuff when i get into play mode but once that loading was over i wasnt able to click anything anymore.

    I hope that someone can help me or point me to right direction.

    Thanks.
     
  2. Vertig0

    Vertig0

    Joined:
    Oct 20, 2018
    Posts:
    6
    I am having this issue as well. Hovering changes the style, but clicking does nothing. Changing to IMGUI events makes it work with the keyboard, but still not working on mouse click. I am on 2020.1.0b6.
     
    Last edited: Apr 25, 2020
  3. mrSaig

    mrSaig

    Joined:
    Jan 14, 2010
    Posts:
    68
    same here ... code works with mouseclick in Editor Window but not in Runtime ... also works when using the return key in runtime but not with mouseclick
     
  4. Flipps

    Flipps

    Joined:
    Jul 30, 2019
    Posts:
    51
    I am on 2019.3.0f3 and it doesn't seem to work, too. (but just started with UI Toolkit)
    Any feedback on this?
     
  5. mrSaig

    mrSaig

    Joined:
    Jan 14, 2010
    Posts:
    68
    nothing yet ... in the new beta b7 its still not working

    My Workaround is to have Buttons in the ListItemElement and have a clicked event on there
     
  6. Omniaffix-Dave

    Omniaffix-Dave

    Joined:
    Jan 11, 2019
    Posts:
    7
    Same issue still occurring as of 2020.1.0b11 "com.unity.ui.runtime": "0.0.4-preview",
     
  7. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Same issue at Unity2022.2.2f1.
    Did you find why I can not select at runtime?
     
  8. cpalma-unity

    cpalma-unity

    Unity Technologies

    Joined:
    Nov 30, 2020
    Posts:
    110
    Hey @watsonsong. Could you give us more details about your setup? It doesn't work in play mode or in a build? Also, can you share how you are setting up the list view?
     
  9. RagnarNI

    RagnarNI

    Joined:
    Nov 1, 2019
    Posts:
    1
    Hi I have found the same.

    My visual element is built at runtime here is my tree (created uxml file to house just view for testing)

    upload_2023-2-3_8-13-28.png

    When a player clicks find game it populates a list of Lobbies (UGS).

    Find Games - Runtime

    upload_2023-2-3_8-26-9.png

    here is dummy code only used in editor

    upload_2023-2-3_8-15-57.png

    This worked using 2022.1 but stopped when using 2022.2+. I changed the callback from
    onSelectionChange to selectionChanged as per docs. I am now on 2022.5.
     

    Attached Files:

  10. Charles1980

    Charles1980

    Joined:
    Oct 7, 2017
    Posts:
    1
    So, is there anyone solve this issue?
     
  11. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    I ran into this with Unity 2022.3.5f1. The first click would select the proper item but subsequent mouse clicks were ignored.

    Fixed by registering handlers for BOTH "itemsChosen" and "selectedIndicesChanged".
    The handler for itemsChosen does nothing (but you must have it in order for selectedIndicesChanged to fire reliably).
    The handler for selectedIndicesChanged is where my logic is at.
     
    Krosenut and oscarAbraham like this.
  12. nathanAjacobs

    nathanAjacobs

    Joined:
    Feb 18, 2019
    Posts:
    9
    Can guarantee that registering handlers for both "itemsChosen" and "selectedIndicesChanged" fixes the problem.

    It shouldn't be required to implement both handlers. In my case I only need the "selectedIndicesChanged" handler.
     
  13. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    389
    I confirm, this workaround works perfectly although understandable! Thanks tigger.

    Code (CSharp):
    1.   lvHistoric.itemsChosen += (IEnumerable<object> selectedRows) =>
    2.    {
    3.        Debug.Log($"itemsChosen {selectedRows.Count()}");
    4.    };
    5.  
    6.    // Selection change, load request and answer field
    7.    lvHistoric.selectionChanged += (IEnumerable<object> selectedRows) =>
    8.    {
    9.        Debug.Log($"selectionChanged {selectedRows.Count()}");
    10.        // My logic here ...
    11.    };