I'm making a test program that allows the user to switch .allowCameraControl on and off with a button So I'm using observable objects that update the scene object whenever a variable changes. But every time the .allowCameraControl option is changed, the scene refreshes and objects goes back to its original orientation. How do I make it so that the object stays in its current orientation even when the .allowCameraControl changes
Here's a minimum reproducible example ContentView.swift:
import SwiftUI
import SceneKit
final class Lmao: ObservableObject {
@Published var yo: SceneView.Options = [.allowsCameraControl]
}
struct ContentView: View {
@EnvironmentObject var l: Lmao
var scene = SCNScene(named: "myScene.scn")
var body: some View {
VStack {
SceneView(scene: scene, options: l.yo)
.frame(width: UIScreen.main.bounds.width ,
height: UIScreen.main.bounds.height / 2)
Button("allow/disable camera controll") {
if l.yo == [] {
l.yo = [SceneView.Options.allowsCameraControl]
}
else {
l.yo = []
}
}
}
}
func updateLocation(_ location: CGPoint) {
print(location)
}
}
CameraTestApp.swift:
@main
struct CameraTestApp: App {
@StateObject private var ll = Lmao()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(ll)
}
}
}
myScene.scn: put some random stuff in a scene file