I have a RealityKitView, and I want to update my scene when some @State value has changed, but I only want to take this action on the frame that the change happens. assuming I have something like
@State private var someState = false
in my update I want to take actions like this.
RealityView { content in
// Add the initial RealityKit content
} update: { content in
//I want to do something only when someState has changed.
if(someState != lastValueForSomeState){
//do something to my content that Is expensive and
//shouldn't happen every time state changes
}
lastValueForSomeState = someState
}
I am aware that I can use the .onChange(of:) modifier to do normal ui operations, but I don't know where or if I can declare it in a place where I have access to the RealityKitContent.
I can also imagine ways I could do this with components and systems, but it seems like I should be able to do this without going there. is there some mechanism I'm missing for this?