You can just store a reference to the entity within your ViewModel and then modify the entity within it.
Quick example here:
http://github.com/thilojaeggi/ResizableCube/
Post
Replies
Boosts
Views
Activity
Maybe I'm confusing something, but the way I add models to my RealityView, is to have a rootEntity, that's managed by my ViewModel, which within I just add more entities.
I don't use any anchors anywhere as of now.
Since you all seem to have access to the Beta, does it allow for you to combine it with SwiftUI views?
Actually, using the new @Observable seems to be a better choice for this, I used it like this:
import Foundation
import RealityKit
import Combine
import Observation
@Observable
class HungerComponent: Component {
var hungerValue: Int = 100
var passedTime: TimeInterval = TimeInterval(0)
let updateInterval: TimeInterval = TimeInterval(2)
required init(hungerValue: Int = 100) {
self.hungerValue = hungerValue
}
}
And then I simply access it within my ViewModel like this:
init(character: Character) {
character = character
self.hungerComponent = character.entity?.components[HungerComponent.self] ?? HungerComponent()
}
Which makes it accessible within the View like this:
Text("Hunger: \(viewModel.hungerComponent.hungerValue)")
Still unsure about what the use of the update closure actually is.
I just store a reference to the just added entity and then modify that, works for me.
Found out how to do it, but not sure if this is the correct way.
This is my component now:
class HungerComponent: Component {
var hungerValue: Int = 100
var passedTime: TimeInterval = TimeInterval(0)
let updateInterval: TimeInterval = TimeInterval(2)
var hungerPublisher = PassthroughSubject<Int, Never>()
required init(hungerValue: Int = 100) {
self.hungerValue = hungerValue
}
func decreaseHunger() {
hungerValue -= 1
hungerPublisher.send(hungerValue)
}
}
And I just add a sink to it in my view:
init(cube: Cube) {
self.cube = cube
if let entity = cube.entity, let hungerComponent = entity.components[HungerComponent.self] {
hungerComponent.hungerPublisher
.sink(receiveValue: { [weak self] hungerValue in
self?.hungerPercentage = Float(hungerValue) / 100.0
})
.store(in: &cancellables)
}
}
If you found out any other way please do tell how.
You could either disable "Enable Multiple Windows" , use a State variable or check if the Window is already open programmatically.
What if I want something to stick out though?
Here: https://developer.apple.com/documentation/visionos
So is Beta 2 coming anytime soon?
This is still there and i don't know why.
I've also noticed this behaviour and believe it to be a bug.
Also, are you using a NavigationStack there or something else?
visionOS doesn't give Applications camera passthrough as of now which means you won't be able to scan QR Codes.
Also interested in this especially for pathfinding/environment mapping.
I assume you could theoretically play Animations and then move it around but that seems kind of "hacky" in a way, wish Reality Composer Pro had something like ragdoll support.
Using Unity with PolySpatial (when it becomes available) might be an option but I don't think you can integrate Windows with it.