Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.07k stars 1.15k forks source link

Creating persistent reference points and scale of the objects #3

Closed Aupuma closed 6 years ago

Aupuma commented 6 years ago

Hi, I have seen that this package has just been released, and I want to use this instead of native ARCore SDK for my project, but I have some questions.

From the samples I know you can call m_SessionOrigin.Raycast to detect the point of the plane you are tapping on. I also know you can create a reference point with the method TryAttachReferencePoint(ARPlane, Pose) from ARReferencePointManager. The pose could be retrieved directly from the raycast but how do I retrieve the ARPlane?

In my game there are multiple levels, and I want to keep a persistent reference point as the the origin position for the levels. In the first scene I want to place the origin tapping on a point of a plane. Then I need to create the anchor there, so when a level loads it changes its position to the anchor one. With ARCore I was able to keep a persistent object, with DontDestroyOnLoad(anchor.gameobject), to do the same with ARFoundation, do I need to put DontDestroyOnLoad() on the reference point, or when it is created it becomes a child of the ARSessionOrigin?

And when I load a new level, If I need it to be in the scale of the AR Session Origin, do I need to make it a child of the trackablesParent from m_SessionOrigin?

ghost commented 6 years ago

The pose could be retrieved directly from the raycast but how do I retrieve the ARPlane?

The ARRaycastHit gives you a TrackableId. You can use ARPlaneManager.TryGetPlane to get the plane.

In my game there are multiple levels, and I want to keep a persistent reference point as the the origin position for the levels. In the first scene I want to place the origin tapping on a point of a plane. Then I need to create the anchor there, so when a level loads it changes its position to the anchor one. With ARCore I was able to keep a persistent object, with DontDestroyOnLoad(anchor.gameobject), to do the same with ARFoundation, do I need to put DontDestroyOnLoad() on the reference point, or when it is created it becomes a child of the ARSessionOrigin?

Sounds like you want the entire session to persist between level loads. You can use DontDestroyOnLoad on the ARSessionOrigin and ARSession (if they are on different GameObjects), though DontDestroyOnLoad is no longer the recommended way to achieve this. See this writeup for more information.

Aupuma commented 6 years ago

Okey, I was able to create the reference point where I wanted with the TryGetPlane method. However, changing the scale of ARSessionOrigin doesn't seem to scale the objects...

ghost commented 6 years ago

What objects are you trying to scale?

The point of the ARSessionOrigin is to scale the camera and the trackables (planes, reference points, and feature points) together, which makes the rest of your content (not under the ARSessionOrigin look bigger or smaller without actually changing it. Nothing under the ARSessionOrigin will be apparently scaled, so you should not expect anything under a reference point, for example, to appear scaled.

Aupuma commented 6 years ago

Problem solved, if I instantiate the object without making it a child of the ARSession Origin the scale works perfectly, thanks!!!!!