Search Unity

Question Visual elements other than button seem to not be working for ClickEvent callbacks

Discussion in 'UI Toolkit' started by osimaleki, Mar 24, 2021.

  1. osimaleki

    osimaleki

    Joined:
    Jan 15, 2020
    Posts:
    35
    This used to work for me but it doesn't anymore in preview version 14. Am I going crazy?

    rootVisualElement.Q<VisualElement>("label-line", "loginScreen")?.RegisterCallback<ClickEvent>(ev => CreateAccountLinkClick());

    Any other way to get press events for other visual elements?

    Thank you!
     
  2. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,003
    It works here. I'd double-check that the Q<> query doesn't return null, otherwise the registration will be silently skipped because of the "?.".

    If it still fails, can you share a small project that shows the same behavior?
     
  3. osimaleki

    osimaleki

    Joined:
    Jan 15, 2020
    Posts:
    35
    Thank you for the response! So far I have narrowed down the issue to how I am nesting each screen under a 'screen manager' UXML.

    When I do that, the labels are visible but as if they don't have 'space' to click. Going to try to see what I am doing wrong. I will post here when I solve for anyone else who might run into this.
     
  4. osimaleki

    osimaleki

    Joined:
    Jan 15, 2020
    Posts:
    35
    Yes definitely a container (visual element) height issue. Forced the height with an inline setting and all good.
     
    mcoted3d likes this.