Dynamically add arobject to use with ARKit Object recognition

Is it possible to dynamically add ".arobject" to use in the object recognition capability released in Arkit 2.0. i am using ARKit sdk with Unity. i want to load " .arobject ". which can be retrive after scanning object using UnityObjectScannerscene which comes with ARKit 2.0 sdk. i want to load these .arobject files either from server or from local device path at runtime and use these ".arobjects" as the source for object detection.

Yes this is possible in ARKit 2.0, once you have a URL to your .arobject, you can create an ARRefrenceObject using https://developer.apple.com/documentation/arkit/arreferenceobject/2977513-init


You would then add the reference object to your configuration's detectionObjects.


I'm not sure what that looks like in Unity's ARKit Plugin, but it should be similar.

Thank you for your replying.


There is no method to do this in Arkit's plugin for unity.

I am able to modify Arkit's native code. following code is for creating refrenceObject.. (code provided with Arkit sdk, haven't change the code just modifing url)

NSData *rodata = [NSData dataWithContentsOfURL:url options:NSDataReadingMappedAlways error:&error];

         if (error)
             NSLog(@"ProblemInLoading ... %@", error);

ARReferenceObject* referenceObject = [NSKeyedUnarchiver unarchiveObjectWithData:rodata];

return (__bridge_retainedvoid*) referenceObject;




when i pass URL or local path of .arobject file it returning following error


The file “objScan_1.arobject” couldn’t be opened because there is no such file.


i've checked file is located on URL or local path but it returning the error in following line

ARReferenceObject* referenceObject = [NSKeyedUnarchiver unarchiveObjectWithData:rodata];

This snippet demonstrates the proper way to add to your referenceObjects at runtime, and will work assuming that "test.arobject" is in your main bundle and is added to your app's target.


override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
       
        // Create a session configuration
        let configuration = ARWorldTrackingConfiguration()
        guard var referenceObjects = ARReferenceObject.referenceObjects(inGroupNamed: "AR Resources", bundle: nil) else {
            fatalError("Missing expected asset catalog resources.")
        }
        guard let url = Bundle.main.url(forResource: "test", withExtension: "arobject") else {
            fatalError("Missing expected asset in main bundle.")
        }
        do {
            let newReferenceObject = try ARReferenceObject(archiveURL: url)
            referenceObjects.insert(newReferenceObject)
        } catch {
            fatalError("Failed to create reference object from archiveURL.")
        }
        configuration.detectionObjects = referenceObjects

        // Run the view's session
        sceneView.session.run(configuration)
    }
Dynamically add arobject to use with ARKit Object recognition
 
 
Q