Search Unity

How To Pass Clicks Through an Image ?

Discussion in 'UI Toolkit' started by FuguFirecracker, Apr 14, 2020.

  1. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    I can :

    Code (CSharp):
    1. var button = new Button();
    2. button.Add(new Image{image = myImage});
    result : I can click on the image in the button and the click does indeed pass through to the button.

    Code (CSharp):
    1. var toggle = new Toggle();
    2. toggle.Add(new Image{image = myImage});      
    result: image blocks clicks to the toggle parent.

    How do I ignore the Image, as the button implementation does, and pass the click on through to the toggle ?

    Thanks
     
  2. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
    Set the Picking mode of the image to ignore. That's
    <Image picking-mode="Ignore"/>
    in uxml or
    image.pickingMode = PickingMode.Ignore;
    in C#
     
    manuelgoellnitz likes this.
  3. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Thanks for the reply.
    I did try that prior to posting.
    Does not do the thing that one suspects it might do.

    Nor does delagateFocus = false in the parent do what one would expect.
     
  4. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    398
    This feels like a bug. Can you submit a bug report with Help->Report a bug and send us you small repro?

    In the meantime, you can do something like this in c#

    image.AddManipulator( new Clickable( ()=> toggle.value = !toggle.value));
     
    FuguFirecracker likes this.
  5. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Merci, uMathieu.
    I shall attempt your solution and put together a bug report later this evening.

    *edit*
    Works !
     
    Last edited: Apr 15, 2020