Why can't I load a ModelEntity from RealityKitContentBundle?

If I place the .usdz file in the project directory alongside other .swift files, ModelEntity loads it perfectly. However, if I try to load the same file from Reality Composer Pro under RealityKitContent.rkassets, I get the error: resourceNotFound("heart").

Could someone help me with this? Thank you so much

Code:

//
// TestttttttApp.swift
// Testtttttt
//
// Created by Zhendong Chen on 2/17/25.
//
import SwiftUI
@main
struct TestttttttApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.windowStyle(.volumetric)
}
}
//
// ContentView.swift
// Testtttttt
//
// Created by Zhendong Chen on 2/17/25.
//
import SwiftUI
import RealityKit
import RealityKitContent
struct ContentView: View {
@State private var enlarge = false
var body: some View {
RealityView { content in
do {
// MARK: Work
let scene = try await ModelEntity(named: "heart")
content.add(scene)
// MARK: Doesn't work
// let scene = try await ModelEntity(named: "heart", in: realityKitContentBundle)
// content.add(scene)
} catch {
print(error)
}
}
}
}
#Preview(windowStyle: .volumetric) {
ContentView()
}

Hello @WeAreAllSatoshi

My first recommendation would be try using Entity(named: in: ) to see if you can load your asset that way. There are some differences in how ModelEntity(named: in: ) loads model entities from RCP packages and from the main bundle that may be causing the error you're seeing here.



A ModelEntity is, essentially, an Entity with a ModelComponent, so you should be able to find your ModelComponent on the Entity you load with Entity(named: in: ) and access any necessary data that way (even if the root entity is not technically a ModelEntity - the ModelComponent and mesh data should still exist somewhere in the loaded Entity's hierarchy). Can you elaborate a bit more on what you are trying to do with the entity you're loading? I am happy to give suggestions based on your specific context.



Thank you for your question!

Why can't I load a ModelEntity from RealityKitContentBundle?
 
 
Q