Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Create ARReferencePoint

Discussion in 'Handheld AR' started by DreamEnder, Aug 8, 2018.

  1. DreamEnder

    DreamEnder

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

    rxmarccall

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

    tdmowrer

    Unity Technologies

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

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    36
    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. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    268
    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:
    43
    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
  7. tdmowrer

    tdmowrer

    Unity Technologies

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

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    43
    I am testing on iOS.
     
  9. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    268
    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:
    43
    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. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    268
    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:
    43
    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. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    268
    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:
    43
    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. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    268
    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:
    43
    Thanks for the help, greatly appreciated.