google-ar / arcore-unity-sdk

ARCore SDK for Unity
https://developers.google.com/ar
Other
1.4k stars 400 forks source link

About deleting old trackables and start tracking without any previous data(start like a first try) #181

Closed AnipenHkim closed 6 years ago

AnipenHkim commented 6 years ago

Hi, I'm using ARCore for my project and have some questions.

I want to reset all trackables when application is paused(especially run in background), and I've searched solution for this issue here. The nearest issues about this was "#128 Trackables can not be deleted" and I've watched this issue and found the release note that this issue have been already solved.

release note : Fixed #128: Objects from old sessions are deleted when a new ARCoreSession is created.

But, when I tried to destroy old "ARCoreSession" and create new "ARCoreSession" script, nothing happened. Old trackables were still remains and tracked when ARCore recognized same environment. I also tried to call method "ArSession_destroy" on "SessionApi" script, but app crashed.

Can I know specific process to delete old trackables? or has it been fixed not yet? Please, answer

Thanks, regards

pablisho commented 6 years ago

Hi, to destroy an create a new ARCore Session you have to destroy your ARCoreSession object that is usually attached to ARCore Device and then create a new one. What version of Unity ARCore SDK are you using? You shouldn't be calling internal methods, as we don't guarantee any behaviour on them.

AnipenHkim commented 6 years ago

I've tested exactly what you mentioned. I destroyed "ARCoreSession" and contained object. After that I re-created GameObject contains "ARCoreSession", but still remained trackables(checked it as displaying "Session.GetTrackables with trackable filters All" count)

I'm using Unityj ARCore SDK 1.1 and my unity version is 2017.3.1f1 and tested device is Galaxy S8 & Pixel XL with android 8.1.

pablisho commented 6 years ago

Hi I cannot repro this issue with ARCore SDK for Unity v1.2.0

What I'm doing is something like:

var session = GameObject.Find("ARCore Device").GetComponent<ARCoreSession>(); 
Destroy(session);
var device = GameObject.Find("ARCore Device");
session = device.AddComponent<ARCoreSession>();
session.SessionConfig = // Set config
session.enabled = true

The if you do Session.GetTrackables<DetectedPlane>(planeList); gives me an empty list. Keep in mind that if you have old references to objects that belong to the previous session you have to destroy those objects too, but that's a visualization issue, ARCore is not returning them anymore.

pablisho commented 6 years ago

Hi, I'm closing due to inactivity and that I cannot repro with ARCore SDK for Unity v1.2.0. Please feel free to reopen if you still experience the issue.

NicolasWipon commented 6 years ago

Hi, I tried to destroy and create a new Session with these lines in a coroutine :

ARCoreSession session = goARCoreDevice.GetComponent<ARCoreSession>();
        ARCoreSessionConfig myConfig = session.SessionConfig;
        Destroy(session);

        yield return null;

        session = goARCoreDevice.AddComponent<ARCoreSession>();
        session.SessionConfig = myConfig;
        session.enabled = true;

However, when I do this, the app is frozen for several seconds. Then, sometimes it works as expected, but sometimes the camera doesn't work anymore and is frozen on the last frame captured before the creation of a new session.

Is there another way to reset the scan from the beginning (and not keep the previous scanning data) ? Tested with ARCore SDK for Unity v1.2.0 on Galaxy S7 and S7 Edge.

Pn-io commented 6 years ago

Hi, I tried the same above-mentioned code of pablisho and as soon as this code runs camera stops working.

krychaszek commented 6 years ago

Hi, Is there any way for resetting previous session data? I want to reset data about found planes, and trackables, but when I'try the solution above I have the same situation as @NicolasWipon - camera doesn't work anymore and it is frozen.

leonmiura commented 6 years ago

For me pablisho's code almost worked, but I had to replace Destroy(session); with DestroyImmediate(session);.

What happens is that Destroy waits until the end of the frame to actually destroy the object. So when you try to create a new session, you get an error saying that there cannot be 2 ARCore sessions in one scene, and it destroys the new one... when you reach the end of the frame the old one is destroyed and I think that is why the camera is frozen afterwards.

When you call DestroyImmediate instead, the session is actually deleted immediately as you might have expected (I sure did) and the new session can be created fine.

(I got the idea of using DestroyImmediate from this thread: https://answers.unity.com/questions/840932/component-not-destroyed.html)