Trouble loading ModelEntity from RealityKitContent package

Hi,

I'm working on a simple visionOS app and I'm testing on device.

For one part of the app, I load an object in and place it on the user's hand. If I use a primitive shape, like a sphere or cylinder, this works fine. However, now I'm trying to load a an object from my RealityKitContent package. But everytime I try this, I get a an error message, resourceNotFound("Stone"), where "Stone" is one of my usda scenes.

This is what the guts of my function looks like that should return a ModelEntity:

do {
            
       let entity = try await ModelEntity(named: "Stone", in: realityKitContentBundle)
       entity.generateCollisionShapes(recursive: true)
        return entity
 } catch {
        print("Error \(error)")
 }

I can see the "Stone" in my Xcode sidebar as part of the RealityKitContent package and inside that scene, there is a simple sphere, but alas I always get this in the Xcode console, "Error resourceNotFound("Stone")"

I'm probably doing something pretty silly, hopefully it's obvious to someone else.

Thanks for the help.

  • Ian

Try this. If it doesn't work, it should at least spit out some useful error information in the console at run time.

            do {
                let entity = try await Entity(named: "Stone", in: realityKitContentBundle)
                content.add(entity)
                
            } catch {
                print("Error loading stone model: \(error.localizedDescription)")
            }

Thanks for the reply. I'm using this slight code variation, because I really need a ModelEntity for physics stuff instantiated:

 let entity = try await ModelEntity(named: "Stone", in: realityKitContentBundle) 

And this is the error I get:

Error Failed to find resource with name "Stone" in bundle

Any other thoughts?

Hi! I stumbled upon the same problem, and I think I've found a solution: In the Model File Inspector (on the right side when you click on the model file), there's a 'Target Membership' section. Just check the box for your application there. That's it!

Trouble loading ModelEntity from RealityKitContent package
 
 
Q