A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Introducing the new Universal Render Pipeline and High Definition Render Pipeline subforums!
Unity 2019.3 Beta is out now.
Discussion in 'Handheld AR' started by DreamEnder, Aug 8, 2018.
How would you go about creating a reference point/anchor from script?
I've wondered this as well!
ARReferencePointManager.TryAddReferencePoint and ARReferencePointManager.TryAttachReferencePoint
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?
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.
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.
_stageReferencePoint = ReferencePointManager.TryAttachReferencePoint(_planeHit, _hitPose);
After the above code is run _stageReferencePoint is still null;
_stageReferencePoint = ReferencePointManager.TryAddReferencePoint(_hitPose);
This does return a ReferencePoint for me instead of null, so this one appears to be working.
Arkit or ARCore?
I am testing on iOS.
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.
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
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?
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.
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?
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.
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).
Disabling the ARPlaneManager will tell the device to stop detecting planes, so I wouldn't expect any further updates to the ReferencePoint.
Thanks for the help, greatly appreciated.
@tdmowrer Hey, I am wondering if I should be making use of a reference point to improve tracking, or just better practice.
I am currently placing my content using standard place on plane method, turning off plane manager and making use of makecontentappearat for scaling.
All is working well, but sometimes I suffer floating,jittering or relocating, and reference points have been mentioned as a way to improve tracking.
My understanding is I am placing my content at a specific world space coord, and the arsession and trackposedriver looks after the tracking relative to the cameras movement after that etc.
What would a reference point add? Can it be used in this case? Would it be better?
Would you mind providing a simple explanation/comparison of a simple point in world space vs a referencepoint(anchor) to help my understanding of things.
Thanks a lot
@tdmowrer If you get time, can you offer any insight to my question above.
Thanks a lot
What I don't get:
If the reference points are essential, why are they not included in the sample scenes? I had to google my way over here with a lot of detours until I found out.
It's the same with remoting:
You guys updated the thread with a video, but kinda forgot to mention that they are broken in 2019, took me 2h to find that out.
Sorry, had to say this, I´'ll try the reference points now.
Sorry, what's broken in 2019? Can you link me to the video?
I agree a sample would be helpful. I'll see what we can do about that.
Everyone in this thread was experiencing the same errors as me, the consensus was: broken in 2019. Since I didn't find anything about it, I assumed this was the case.
The video I was referring to is on page 1.
hello.. @tdmowrer ..Help me understand the advantage of adding a reference point(anchor point) to a object
for example,1. we can place a cube by simply after a hit test, like instantiating a cube after a raycast hit on the trackable type plane and setting the position and rotation of the cube to the returned hit pos and rotation ,device can start tracking that cube........ does it improve/ make any difference in tracking, if we add a reference point to that hit position ???
2. we can place a cube(not hit test) just 1 unit in front of the camera at the start itself and it will start tracking that cube relative to the world origin(position and rotation of the device when session starts), does it improve tracking if we add a reference point to that position ??????( for the test case i have done i cant observe much difference)
3.ar core doc says using anchors improves realism and performance, but when the environment understanding changes in each frame position and rotation of these anchor also may changes ,so in effect the position of the objects using this anchor/reference also prone to the changes .... a possibility of drift may occur like a an object without anchor ryt?????
I have used anchors only in ARCore, but I assume they are similar here.
If the track of the scene has been less than optimal before you place your object, there is a chance that the point cloud and therefore the transforms of the trackables change. An Anchor will be notified of the changes and change its pose relative to the the new tracking points' location.
Hey @ArmanUnity I'm testing anchors with ARF2.1 and frankly not yet seeing much difference on tracking. Where I can see the benefit of anchors is if two objects are to maintain a specific distance to each other - by anchoring both objects as child of the anchor it would help be "more realistic" because both objects can keep their position relative to one another constant cos they're both child of the parent anchor; that's the example in arcore https://developers.google.com/ar/develop/developer-guides/anchors
That's my interpretation to date.
yes @Tarrag i understand the advantage if we need to maintain distance between two objects ... but in ar core doc they saying that .... you should place an anchor on the hit position place ...ryt????
"For example, imagine that your app lets users place virtual furniture pieces around a room. A user opens the app and ARCore begins tracking a tabletop and a floor in the room as Planes. The user positions a virtual lamp on the tabletop. Then, the user puts a virtual chair on the floor.
At this point, your scene should have one anchor attached to the tabletop Plane and another attached to the floor Plane."
so for the normal hit test on a plane ... we can change the objects position to hit position and and start tracking, And we can also add a reference point in there and make object as child of reference point game object.. does the second way improves tracking .....???? i cant see much difference
@ArmanUnity Check my answer above. The anchor points stay fixed in world space (what you see through the phone), while the planes may change position in the Unity scene. Connect your phone via google instant preview and track a not-so-optimal environment. You may run into this situation. The anchors are for "safety".
@Blenderik ,i have seen your answers ... i will debug it with optimal environment and confirm.... but i think when the environment understanding changes anchor position also changes ,so is the position of the child game objects also experience a shift/drift in position ryt??
The best usage for anchor is to "anchor" them directly with the plane you just found...this is because if you move in place and the plane become more and more precise with your real world enviroment this could help your object to stay in the right spot.
@AlbyDj90 ,ok good .... does it improves tracking with out planes..... ie. like a floating cube in air with a anchor point associated with it