Thanks to https://developer.apple.com/forums/thread/733918
(I tested this snippet in Vision Pro lab and it worked.)
extension Entity {
public func setGroundingShadow(_ castsShadow: Bool) {
self.enumerateHierarchy { entity, stop in
if entity is ModelEntity {
entity.components.set(GroundingShadowComponent(castsShadow: castsShadow))
}
}
}
private func enumerateHierarchy(_ body: (Entity, UnsafeMutablePointer<Bool>) -> ()) {
var stop = false
func enumerate(_ body: (Entity, UnsafeMutablePointer<Bool>) -> ()) {
guard !stop else {
return
}
body(self, &stop)
for child in children {
guard !stop else {
break
}
child.enumerateHierarchy(body)
}
}
enumerate(body)
}
}