@Vision Pro Engineer thanks for this, it helped a lot! For me and maybe it's because I was using a primitive from Reality Composer Pro, my entity's structure was a bit different:
⟐ SynchronizationComponent
⟐ CollisionComponent
⟐ InputTargetComponent
⟐ Transform
▿ 'usdPrimitiveAxis' : ModelEntity
⟐ SynchronizationComponent
⟐ ModelComponent
⟐ Transform
So to get the model component I would have used:
var model = cube.children.first?.components[ModelComponent.self]
or also use this to get the index:
let index = cube.children.firstIndex(where: { $0.name == "usdPrimitiveAxis"})
and then use that to get the reference from the children set
Post
Replies
Boosts
Views
Activity
This only happens on the preview right? For a good explanation: https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-54-crash-in-preview-of-swiftdata/26510/27172
TLDR; in the preview you're not initializing the container, so you'll need to:
#Preview {
ContentView()
.modelContainer(for: Student.self)
}