@tracyhenry I think I figured it out.
I think I figured out the problem through experimentation, and GroundingShadowComponent actually does work.
I think when you read a model from a USDZ file, you can't simply assign the GroundingShadowComponent to the root entity of the entity hierarchy that's in the USDZ file. GroundingShadowComponent must be assigned to each ModelEntity that's in the USDZ file hierarchy.
This would explain why GroundingShadowComponent worked when directly assigned to sphereEntity in your code, because it's a ModelEntity.
Assuming the existence of Entity/enumerateHierarchy, defined below, you could write something like this after you load the entity from the USDZ file:
usdzFileEntity.enumerateHierarchy { entity, stop in
if entity is ModelEntity {
entity.components.set(GroundingShadowComponent(castsShadow: true))
}
}
This worked for me when I tried it.
import RealityKit
extension Entity {
/// Executes a closure for each of the entity's child and descendant
/// entities, as well as for the entity itself.
///
/// Set `stop` to true in the closure to abort further processing of the child entity subtree.
func enumerateHierarchy(_ body: (Entity, UnsafeMutablePointer<Bool>) -> Void) {
var stop = false
func enumerate(_ body: (Entity, UnsafeMutablePointer<Bool>) -> Void) {
guard !stop else {
return
}
body(self, &stop)
for child in children {
guard !stop else {
break
}
child.enumerateHierarchy(body)
}
}
enumerate(body)
}
}