Post

Replies

Boosts

Views

Activity

Reply to Game Center breaks RealityView world tracking
I found that the issue is not limited to RealityView, it also occurs with ARView. I discovered this when I wrote an ARView wrapper as a possible workaround, but spatial tracking and camera feed of an ARView are also broken if GKLocalPlayer.local.authenticateHandler has been set: struct RealityARView: UIViewRepresentable { var setupARContent: (RealityARView) -> Void private var anchor: AnchorEntity private var sessionConfig = ARWorldTrackingConfiguration() init(setupARContent: @escaping (RealityARView) -> Void) { self.setupARContent = setupARContent self.anchor = AnchorEntity(world: [0, 0, 0]) } func makeUIView(context: Context) -> ARView { let arView = ARView(frame: .zero) arView.scene.addAnchor(anchor) arView.cameraMode = .ar arView.environment.background = .cameraFeed() sessionConfig.planeDetection = [] arView.session.run(sessionConfig) setupARContent(self) // Call the content setup closure return arView } func updateUIView(_ uiView: ARView, context: Context) { } static func dismantleUIView(_ uiView: ARView, coordinator: ()) { uiView.session.pause() } public func add(_ entity: Entity) { anchor.addChild(entity) } } struct ImmersiveARView: View { var body: some View { RealityARView { content in var material = SimpleMaterial() material.color = .init(tint: .blue) let sphereMesh = MeshResource.generateSphere(radius: 0.1) let entity = ModelEntity() entity.components.set(ModelComponent(mesh: sphereMesh, materials: [material])) entity.position = [0.0, 0.0, -1.0] content.add(entity) } } }
Aug ’24
Reply to RealityView world tracking without camera feed?
I tried, but the skybox doesn't show up if the camera is set to world tracking. To reproduce the issue, open the BOT-anist sample project and add content.camera = .worldTracking in ExplorationView.swift ca. line 57 (above the code that sets the environment). I tried that with Xcode 16.0 beta 5, iPadOS 18 beta 6, on iPad Pro 11" 3rd gen, and the background shows the camera feed instead of the skybox. Is this a bug?
Aug ’24
Reply to RealityKit Subdivide
I'm wondering the same thing. It would be great if generateSphere would make use of surface subdivision, dynamically adjusting depending on the distance to the camera... but there is nothing in the documentation that tells us what "subdivision surface" actually means for RealityKit 4.
Jul ’24
Reply to iOS 18 SwiftData ModelContext reset
I filed FB14130653 with a minimal example project, and referenced the FB that @ashinthetray reported already. Having thought about this some more, I retract my previous statement about my solution having improved the my code. I realized that now, without using @Environment, my code doesn't make use of SwiftData's simple model access in SwiftUI at all. This looks like a regression in the iOS 18 beta round (and visionOS 2, tvOS 18, macOS 15), and not like an intentional change.
Jun ’24
Reply to iOS 18 SwiftData ModelContext reset
I got the exact same error message and resolved it by changing the way I create and keep my ModelContainer. Cause: Before, I created it in ContentView like this: NavigationStackView() .modelContainer(MyModelContainer.create()) and accessed it in all other views via @Environment(\.modelContext) private var modelContext MyModelContainer.swift looked like this: actor MyModelContainer { @MainActor static func create() -> ModelContainer { let schema = Schema([MyModel.self]) let configuration = ModelConfiguration("foo", url: FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!.appendingPathComponent("foo.store")) let container = try ModelContainer(for: schema, configurations: [configuration]) // ... fill it ... SomeSingleton.shared.modelContext = container.mainContext // Other classes need model access too return container } } I have 2 models, but I've ruled that out as a cause. I also ruled out that @Environment causes it, because the crash happened even if only my SomeSingleton accessed the modelContext. Solution: For me, the solution was to make container a member of MyModelContainer, which I turned into a Singleton: @MainActor class MyModelContainer { static let shared = MyModelContainer() let container: ModelContainer private init() { let schema = Schema([MyModel.self]) let configuration = ModelConfiguration("foo", url: FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!.appendingPathComponent("foo.store")) container = try ModelContainer(for: schema, configurations: [configuration]) // ... fill it ... } } In other places (another Swift class, and SwiftUI), I access it via MyModelContainer.shared.container.mainContext. In SwiftUI, I removed all .modelContainer and @Environment lines. I suppose that these modifications might have also improved the thread safety and performance of my code, Apple probably had a reason for this change. I'll also file a bug report as soon as I find the time to build a minimal example project. Hope that helps 🙂
Jun ’24