Search Unity

Making Canvas buttons 'modal' ie trapping touch events

Discussion in 'AR' started by eco_bach, Oct 27, 2017.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Hi
    Anyone doing ARkit development with Canvas buttons?
    I haven't been able to make them 'modal', ie trap touch events so they don't get propagated to your actual 3D world.
     
  2. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    nifilo_unity likes this.
  3. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    Hi

    Had another look at this today in the sample ARKit Balls scene.... for anyone interested, my reply above didn't work in the context of the touch being detected on the generated AR planes.

    I ended up using the IPointerDownHandler interface in the event system.

    https://docs.unity3d.com/ScriptReference/EventSystems.IPointerDownHandler.html

    I added this to the plane prefab... so as planes are generated, they listen for the PointerDown event within their bounds.... and events on UI Buttons don't propagate to these planes.

    Anyone got any better way, let us know
    Cheers
    R
     
  4. baleboy

    baleboy

    Joined:
    Jan 23, 2017
    Posts:
    7
    At least for hit testing the first reply by richie-green above worked fine for me.
     
  5. levilais

    levilais

    Joined:
    Jul 19, 2018
    Posts:
    8
    I know it’s been about a year since you looked into this - but do you remember exactly what you did? The first comment and the second comment reference different solutions but it seems like maybe you did both? I’ve been at this for 3 days now. Do I modify the ARKitHitTest script by adding the stuff from comment 1 and then hunt down the invisible plane prefab and just add the generic script?

    Sorry for all the vague guesses but I’m really trying to figure this one out.
     
  6. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    Hey @levilais

    The first solution should work... Can you post your code where you are detecting clicks/touches and using the IsPointerOverGameObject.

    Are you using ARInterface or the new ARFoundation?

    Thanks