Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

UI buttons in ARcore? (helloAR example)

Discussion in 'ARCore' started by JasonJohn1977, Oct 11, 2017.

  1. JasonJohn1977

    JasonJohn1977

    Joined:
    Aug 12, 2013
    Posts:
    14
    Hello I've been playing with the ARcore examples and am struggling to have a working button, the helloAR example where you can place an "andy" model i've got a button hooked up to swap between different models however whenever this button is hit it also places a model is there a way to tell ARcore to ignore a certain layer / tag I'm really struggling to see it, any advice would be greatly appreciated : )
     
  2. thantieuhodo91

    thantieuhodo91

    Joined:
    Dec 3, 2014
    Posts:
    5
  3. JasonJohn1977

    JasonJohn1977

    Joined:
    Aug 12, 2013
    Posts:
    14
    HenryAsh likes this.
  4. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    180
    Hi @JasonJohn1977,

    @thantieuhodo91 is right -- the issue is that both the UI button and the HelloAR sample both respond to touch input. If you look at HelloARController.cs, around line 132, you'll see that it performs raycasts looking for a place to put the andyObject anytime there is a touch input. This is a good starting point, but to extend it to support the type of logic you're describing, you may want to just copy this code into your own component and only perform the hit test on ARCore planes when the a button is not being pressed. So basically wrap that raycast logic in a

    Code (csharp):
    1. if (!IsPointerOverUIObject()) {...}
    type of statement.

    Cheers,
    Tim
     
  5. JasonJohn1977

    JasonJohn1977

    Joined:
    Aug 12, 2013
    Posts:
    14
    Hi @timmunity

    This fixed my issue, I used the line
    Code (CSharp):
    1. if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId)) {...}
    thanks so much for your help : )
     
  6. jarod-smith

    jarod-smith

    Joined:
    Feb 15, 2018
    Posts:
    1
    Hi, I seem to be having the same issue when adding @JasonJohn1977 's code the prefab simply won't even place. what do you think could be going wrong? For reference here is my code snippet,

    Code (CSharp):
    1.  
    2. if (Session.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit) && doPlace && !EventSystem.current.IsPointerOverGameObject(touch.fingerId))
    3.             {
    4.                 var andyObject = Instantiate(AndyAndroidPrefab, hit.Pose.position, hit.Pose.rotation);
    5.  
    6.                 // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
    7.                 // world evolves.
    8.                 var anchor = hit.Trackable.CreateAnchor(hit.Pose);
    9.  
    10.                 // Andy should look at the camera but still be flush with the plane.
    11.                 andyObject.transform.LookAt(FirstPersonCamera.transform);
    12.                 andyObject.transform.rotation = Quaternion.Euler(0.0f,
    13.                     andyObject.transform.rotation.eulerAngles.y, andyObject.transform.rotation.z);
    14.  
    15.                 // Make Andy model a child of the anchor.
    16.                 andyObject.transform.parent = anchor.transform;
    17.                 doPlace = false;
    18.             }
    19.  
     
  7. aakashdabrase

    aakashdabrase

    Joined:
    Aug 31, 2017
    Posts:
    3
    Don't add the condition in above if statement using &&. Just wrap raycast using if(!EventSystem.current.IsPointerOverGameObject(touch.fingerId)){...}
    Also check your doPlace var, maybe its always false
     
    Last edited: Feb 16, 2018
  8. tinatotty91

    tinatotty91

    Joined:
    Jul 26, 2018
    Posts:
    1
    Hi, sorry for the dumb question but I'm a complete beginner. I'm trying to create a item menu for a AR scene in Unity. In my scene you can choose between different 3D items in a list and than spawn the corrisponding item when I touch a tracked plane in the app. When I try to spawn a single tipe of 3D object it works (basically like helloAR), but I can't figure out how to make it work with a list of objects.
    Thanks!
     
  9. danigidiu

    danigidiu

    Joined:
    Jul 31, 2018
    Posts:
    2
    Hi,My problem is similar I want to create a button with a list of objects from where to select different objects and put them in the real world. Can someone help with a script or instructions to do that?
     
  10. danigidiu

    danigidiu

    Joined:
    Jul 31, 2018
    Posts:
    2
    @jarod-smith Do I get error with Raycast and doplace?Can you send me all your code?