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. Dismiss Notice

Question How dose an element block ClickEvent while its parent's pickingmode is set to Ignore?

Discussion in 'UI Toolkit' started by ZetanHwang, Jul 24, 2022.

  1. ZetanHwang

    ZetanHwang

    Joined:
    Oct 11, 2016
    Posts:
    7
    In some case I need to set the pickingmode of parent to Ignore, but its children need to be clickable
     
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    Actually this should be the behaviour of pickingMode = Ignore. It only affects the element, not its children.
     
  3. ZetanHwang

    ZetanHwang

    Joined:
    Oct 11, 2016
    Posts:
    7
    Thanks, but I don't know why it doesn't work for me, I had tried it before.
    Here's what I'm doing:
    Code (CSharp):
    1. root.Add(errors = new VisualElement());
    2. errors.pickingMode = PickingMode.Ignore;
    3. errors.style.position = Position.Absolute;
    4. var label = new Label("some error");
    5. label.style.color = Color.red;
    6. label.RegisterCallback<ClickEvent>(evt =>
    7. {
    8.    //Locate error
    9. });
    10. errors.Add(label);
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,883
    I think you want to make sure you set the useTrickleDown parameter to TrickleDown in your RegisterCallback call, as by default it's BubbleUp.