Search Unity

  1. Unity 2019.1 beta is now available.
    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. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    355
    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?
     
  11. yanwenwen813283348

    yanwenwen813283348

    Joined:
    Tuesday
    Posts:
    1
    hallo I have the same question with you, I would like to add a UI bottom as a menu to select the item. I wonder whether your problem has been solved or not, and how did you deal with it?