Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.02k stars 1.12k forks source link

Dynamically Add XRReferenceObject's from AssetBundle to XRReferenceObject at runtime, and set ARTrackedObjectManager.ReferenceLibrary at runtime on iOS #938

Closed oliverellmers closed 2 years ago

oliverellmers commented 2 years ago

How do I... Dynamically Add XRReferenceObject's from AssetBundle to XRReferenceObject at runtime, and set ARTrackedObjectManager.ReferenceLibrary at runtime on iOS

I am storing XRReferenceObject's within Assetbundles that I am downloading and extractign at runtime. I am generating a new XRReferenceObjectLibrary at runtime, and populating this with the XRReferenceObject's in my AssetBundle, and then setting the ARTrackedObjectManager.ReferenceLibrary with the newly generated XRReferenceObjectLibrary as follows:

XRReferenceObjectLibrary refLib = new XRReferenceObjectLibrary();
refLib.Add(targetObjects[0]);
refLib.name = "TestLib";
arTrackedObjectManager.referenceLibrary = refLib;
arTrackedObjectManager.trackedObjectPrefab = objectTargetPrefabs[0];

foreach (XRReferenceObject obj in arTrackedObjectManager.referenceLibrary) {

    Debug.Log(obj.name);
}

When I run this in Editor and on my iOS device, everything seems to work as it should - the ARTrackedObjectManager has a new XRReferenceObjectLibrary named TestLib, and iterating through the arTrackedObjectManager.referenceLibrary to check comes back positive... but on iOS nothing happens. I recieve no events from arTrackedObjectManager.trackedObjectsChanged += OnTrackedObjectChanged nor are my prefabs spawned at the object targets location.

Any help would be greatly appreciated!

Thanks,

O.

ankur-unity commented 2 years ago

You're following the right steps to create a new XRReferenceObjectLibrary at runtime and add XRReferenceObjects to it.

Are you storing ARKit's .arobject or XRReferenceObject in the AssetBundle? If it's .arobject then you will need to follow the steps listed here: https://github.com/Unity-Technologies/arfoundation-samples/issues/890#issuecomment-947395116

oliverellmers commented 2 years ago

Thank you! Will give this a go tomorrow and let you know how I get on.

Best,

Oliver

Oliver Ellmers Design Technologist

T: +44 (0) 7 481 006 477 E: @. | @. | @.*** W: P http://www.oliverellmers.com/ortfolio http://www.oliverellmers.co | Pretty Lucky http://www.prettylucky.co/ | Good Measure https://www.goodmeasure.xyz/

On Wed, Feb 9, 2022 at 1:20 AM ankur-unity @.***> wrote:

You're following the right steps to create a new XRReferenceObjectLibrary at runtime and add XRReferenceObjects to it.

Are you storing ARKit's .arobject or XRReferenceObject in the AssetBundle? If it's .arobject then you will need to follow the steps listed here: #890 (comment) https://github.com/Unity-Technologies/arfoundation-samples/issues/890#issuecomment-947395116

— Reply to this email directly, view it on GitHub https://github.com/Unity-Technologies/arfoundation-samples/issues/938#issuecomment-1033231201, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4KIK7IQJJ4FRR5EKPICFLU2G6NDANCNFSM5NNS6N3A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

ankur-unity commented 2 years ago

Closing due to inactivity.

chaoslife commented 1 year ago

@oliverellmers Hi, I also encountered the same problem, did you solve it later? I test on 4.2.6,trackedObjectsChanged has no events callback