Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Create ARReferencePoint

Discussion in 'Handheld AR' started by DreamEnder, Aug 8, 2018 at 1:10 PM.

  1. DreamEnder

    DreamEnder

    Joined:
    Apr 12, 2011
    Posts:
    172
    How would you go about creating a reference point/anchor from script?
     
  2. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    254
    I've wondered this as well!
     
  3. timmunity

    timmunity

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    113
  4. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    21
    I am also interested how I can anchor a gameobject using AR Reference Point.
    Is there a scripting example somewhere? I guess the AR Foundation Sample scripts are not setting Reference Points.

    One way is surely to insert the desired prefab to AR Reference Point Manager and instantiate it with the methods that Tim listed above, but then I guess the gameobject changes its name and parent. I'm not sure if that's the right way.

    I was thinking about spawning an gameobject normally, setting an ARReferencePoint in the same place and utilizing ARReferencePointUpdatedEventArgs to get the updated pose to update the gameobject's transform.
    Is that a good way to go?
     
  5. timmunity

    timmunity

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    113
    I would suggest parenting your GameObject to the returned ARReferencePoint (if you don't specify a prefab, it creates a GameObject with only an ARReferencePoint component).

    This would also work, and may be desirable if you plane to scale the ARSessionOrigin.
     
    Saicopate likes this.
  6. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    39
    Curious what the difference is between ARReferencePointManager.TryAddReferencePoint
    andARReferencePointManager.TryAttachReferencePoint? I was using TryAttachReferencePoint thinking that, by referencing a plane, the reference point would automatically update it's position when the plane updates its bounds/position.

    TryAttachReferencePoint is returning null for me though which seems like a bug. I have verified that my plane and pose are not null.

    Code (CSharp):
    1. _stageReferencePoint = ReferencePointManager.TryAttachReferencePoint(_planeHit, _hitPose);
    After the above code is run _stageReferencePoint is still null;

    EDIT:
    Just tried;
    Code (CSharp):
    1. _stageReferencePoint = ReferencePointManager.TryAddReferencePoint(_hitPose);
    This does return a ReferencePoint for me instead of null, so this one appears to be working.
     
    Last edited: Aug 10, 2018 at 1:49 AM
  7. timmunity

    timmunity

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    113
    Arkit or ARCore?
     
  8. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    39
    I am testing on iOS.
     
  9. timmunity

    timmunity

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    113
    It definitely works, but some features will break if you don't include this link.xml file in your project. Attach to plane is one such feature.
     
  10. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    39
    Thanks fixed it, thank you. ReferencePointUpdated started firing after the fix when it was not while using TryAddReferencePoint, not sure if this is intended or not.

    Can you answer my other question above?

    "Curious what the difference is between ARReferencePointManager.TryAddReferencePoint
    andARReferencePointManager.TryAttachReferencePoint?"

    In my app I am placing a single item and want it to appear as if it is in the room with you. I have accomplished this with both calls but I am unsure of the "correct" way to do it. Both of these look like they do the same thing, wonder what are the differences/pros/cons?
     
  11. timmunity

    timmunity

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    113
    Add vs Attach maps closely to these concepts in ARCore: https://developers.google.com/ar/develop/developer-guides/anchors#pick_an_anchor_context

    When you "attach" a reference point to a plane, it maintains that distance from the plane. For example, if the plane is horizontal, then the reference point only moves up and down as the plane's Y position changes. The X and Z coordinates should not change. This is useful for "sticking" objects on or near planes.

    If you "add" a reference point, then you're asking the system to track a specific location in space. It may update if the overall environmental understanding of the session changes.
     
  12. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    39
    Thanks for the help it is appreciated, that was a great explanation. It sounds like i should use TryAttachReferencePoint since I am trying to place something on a table or flat surface.

    Last question, if I attach to a horizontal plane using TryAttachReferencePoint does the returned ReferencePoint take care of it's y position itself? Is there ever any need to do any repositioning with ReferencePointUpdated?
     
  13. timmunity

    timmunity

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    113
    Yes it takes care of the y position. The purpose of reference points is for the device to track and update them. You should not update them manually.
     
  14. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    39
    Ok I lied, one more. After I place my ReferencePoint do I need to keep ARPlaneManager enabled for it to keep updating it's y position.

    Just wondering if shutting down ARPlaneManager after placing a ReferencePoint would improve performance (not that perf is an issue at this point, just trying to be efficient).
     
  15. timmunity

    timmunity

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    113
    Disabling the ARPlaneManager will tell the device to stop detecting planes, so I wouldn't expect any further updates to the ReferencePoint.
     
  16. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    39
    Thanks for the help, greatly appreciated.