Post

Replies

Boosts

Views

Activity

Reply to How do I register undo actions for menu commands while preserving built-in view's undo management?
Some more specific details in case that helps. The key structures are set up in the following pattern. struct MyApp: App { let viewModel = MyViewModel() var body: some Scene { Window { ... } .environment(viewModel) .commands { MyCommands(viewModel: viewModel) } } } struct MyCommands: Commands { let viewModel: MyViewModel() @FocusedValue(\.selectedEntryID) private var focusedID: UUID? var body: some Commands { CommandGroup(...) { Button(...) { viewModel.doSomething(with id: focusedID) } ... } } } struct ContentView: View { @Environment(MyViewModel.self) var viewModel var body: some View { Table(viewModel.records, selection: $viewModel.selectedID) { TableColumn("Column A") { record in TextField("", text: Binding( get: { record.field1 ?? "" }, set: { newValue in record.field1 = newValue } ... } .focusedSceneValue(\.selectedEntryID, viewModel.selectedEntryID) I can verify that there is an UndoManager available to ContentView via @Environment(.undoManager) in the view and adding a button. But it's only present inside the button action, and is nil in .onAppear, for instance, so I don't have an opportunity to inject it into the viewModel before a menu-driven Add action.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’26
Reply to Does VisionOS have the equivalent of ARView.physicsOrigin?
This didn't seem to help with the aggressive damping that the physics simulation does, so I'm not sure it's really scaling? Or maybe I'm just not calling the function with the right arguments. Here's my ImmersiveView definition up to the point where I call your setupPhysicsScaling function. struct ImmersiveView: View { @Environment(AppModel.self) var appModel @Environment(\.realityKitScene) var realityKitScene @State private var subscriptions = Set<AnyCancellable>() var body: some View { RealityView { content in let anchor = namedEntity("Root Anchor") { AnchorEntity() } content.add(anchor) let physicsSimulation = PhysicsSimulationComponent() var sceneRoot = Entity() sceneRoot.components.set(physicsSimulation) sceneRoot.setParent(anchor) setupPhysicsScaling(scene: realityKitScene!, physicsAncestor: sceneRoot)
Topic: Graphics & Games SubTopic: RealityKit Tags:
Mar ’26
Reply to Bouncy ball in RealityKit - game
I'm seeing the same problems in a project. Managed to characterize the issue narrowly enough to report it via Feedback Assistant, since I'm not sure it's been reported yet (FB21197208). Seems to be two main issues to me: Physics simulation stops moving objects during collisions when their velocity is still high enough that it looks quite unnatural (relative velocity around 2.0 or less). Even with everything set such that the collision should produce 100% elasticity, it doesn't. Effect is worse with a box-shaped collider, but still happens with sphere-shaped colliders. Combination of the two means repeated collisions will eventually lead to objects stopping, regardless of the 100% elasticity. Note: I haven't tried the scaling workaround yet, but it sounds like that might just be putting off the issue (more collisions needed to lose enough energy to stop), and I'm starting to think implementing my own movement system would be better (I don't actually need mass/inertia and other true-to-physics behavior, just perfect elastic bouncing).
Topic: Spatial Computing SubTopic: General Tags:
Nov ’25
Reply to How do I register undo actions for menu commands while preserving built-in view's undo management?
Some more specific details in case that helps. The key structures are set up in the following pattern. struct MyApp: App { let viewModel = MyViewModel() var body: some Scene { Window { ... } .environment(viewModel) .commands { MyCommands(viewModel: viewModel) } } } struct MyCommands: Commands { let viewModel: MyViewModel() @FocusedValue(\.selectedEntryID) private var focusedID: UUID? var body: some Commands { CommandGroup(...) { Button(...) { viewModel.doSomething(with id: focusedID) } ... } } } struct ContentView: View { @Environment(MyViewModel.self) var viewModel var body: some View { Table(viewModel.records, selection: $viewModel.selectedID) { TableColumn("Column A") { record in TextField("", text: Binding( get: { record.field1 ?? "" }, set: { newValue in record.field1 = newValue } ... } .focusedSceneValue(\.selectedEntryID, viewModel.selectedEntryID) I can verify that there is an UndoManager available to ContentView via @Environment(.undoManager) in the view and adding a button. But it's only present inside the button action, and is nil in .onAppear, for instance, so I don't have an opportunity to inject it into the viewModel before a menu-driven Add action.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’26
Reply to Does VisionOS have the equivalent of ARView.physicsOrigin?
This didn't seem to help with the aggressive damping that the physics simulation does, so I'm not sure it's really scaling? Or maybe I'm just not calling the function with the right arguments. Here's my ImmersiveView definition up to the point where I call your setupPhysicsScaling function. struct ImmersiveView: View { @Environment(AppModel.self) var appModel @Environment(\.realityKitScene) var realityKitScene @State private var subscriptions = Set<AnyCancellable>() var body: some View { RealityView { content in let anchor = namedEntity("Root Anchor") { AnchorEntity() } content.add(anchor) let physicsSimulation = PhysicsSimulationComponent() var sceneRoot = Entity() sceneRoot.components.set(physicsSimulation) sceneRoot.setParent(anchor) setupPhysicsScaling(scene: realityKitScene!, physicsAncestor: sceneRoot)
Topic: Graphics & Games SubTopic: RealityKit Tags:
Replies
Boosts
Views
Activity
Mar ’26
Reply to Bouncy ball in RealityKit - game
I'm seeing the same problems in a project. Managed to characterize the issue narrowly enough to report it via Feedback Assistant, since I'm not sure it's been reported yet (FB21197208). Seems to be two main issues to me: Physics simulation stops moving objects during collisions when their velocity is still high enough that it looks quite unnatural (relative velocity around 2.0 or less). Even with everything set such that the collision should produce 100% elasticity, it doesn't. Effect is worse with a box-shaped collider, but still happens with sphere-shaped colliders. Combination of the two means repeated collisions will eventually lead to objects stopping, regardless of the 100% elasticity. Note: I haven't tried the scaling workaround yet, but it sounds like that might just be putting off the issue (more collisions needed to lose enough energy to stop), and I'm starting to think implementing my own movement system would be better (I don't actually need mass/inertia and other true-to-physics behavior, just perfect elastic bouncing).
Topic: Spatial Computing SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’25