Thank you for the answer and for the great guidance.
Great that it is possible, and that it will be easy to implement in Reality Composer pro, once it is set up.
I managed to create the Component in Reality Composer Pro, and added the code to ObjectToWorldComponent in Xcode
I run in to some problems after that.
in NameApp I added the lines from your description, but I het to errors of "Cannot find 'ObjectToWorldComponent' in scope" and "Cannot find 'ObjectToWorldSystem' in scope"
Here is the code:
import SwiftUI
@main
struct ankerApp: App {
@State private var appModel = AppModel()
//Kode fra forum som flytter object anker til World Anker
init() {
ObjectToWorldComponent.registerComponent()
ObjectToWorldSystem.registerSystem()
}
var body: some Scene {
WindowGroup {
ContentView()
.environment(appModel)
}
.windowStyle(.volumetric)
ImmersiveSpace(id: appModel.immersiveSpaceID) {
ImmersiveView()
.environment(appModel)
.onAppear {
appModel.immersiveSpaceState = .open
}
.onDisappear {
appModel.immersiveSpaceState = .closed
}
}
.immersionStyle(selection: .constant(.mixed), in: .mixed)
}
}
And in ImmersiveView I get an error saying: "Result of call to 'run' is unused"
That is next to the "await spatialTrackingSession.run(configuration)" line.
Here is the code:
import RealityKit
import RealityKitContent
struct ImmersiveView: View {
let spatialTrackingSession = SpatialTrackingSession()
var body: some View {
RealityView { content in
if let immersiveContentEntity = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
content.add(immersiveContentEntity)
}
}
.task {
// Start a spatial tracking session to obtain permission to query the object and world anchor transforms.
let configuration = SpatialTrackingSession.Configuration(
tracking: [.object, .world])
await spatialTrackingSession.run(configuration)
}
}
}
#Preview(immersionStyle: .mixed) {
ImmersiveView()
.environment(AppModel())
}
I really hope to get some help with the last few issues.
Bedst regards.