``struct CubeView: View {
private var number: Int
init(number: Int) {
self.number = number
}
var body: some View {
let boxSize: Float = 0.1
let cornerRadius: Float = boxSize / 10
let cubeColorTheme = CubeColorTheme.colorPair(for: number)
RealityView { content in
let _ = print("\t\tCreating reality view with \(number)")
let boxEntity = ModelEntity(
mesh: .generateBox(size: boxSize, cornerRadius: cornerRadius),
materials: [
SimpleMaterial(color: UIColor(cubeColorTheme.background), isMetallic: false)
])
let textEntity = ModelEntity(
mesh: MeshResource.generateText(
title(),
extrusionDepth: 0,
font: .systemFont(ofSize: fontSize(), weight: .semibold),
containerFrame: CGRect(),
alignment: .center,
lineBreakMode: .byCharWrapping
),
materials: [
SimpleMaterial(color: UIColor(cubeColorTheme.font), isMetallic: false)
]
)
textEntity.position = textPosition()
boxEntity.addChild(textEntity)
content.add(boxEntity)
} update: { content in
let _ = print("Number updated") // PRINTS FINE
}
}``
Here is my CubeView, which has a RealityView inside of it. I then display this on my window using the following code:
VStack {
ForEach(viewModel.matrix, id: \.id) { cube in
CubeView(number: cube.value)
}
}
I have some other code that changes the number on a cube (Not the ID) and for some reason the cube does not re-render with the new number _but_ the update closure gets called as expected!