ModelDebugOptionsComponent
A component that changes how RealityKit renders its entity to help with debugging.
Declaration
struct ModelDebugOptionsComponentOverview
Attaching a ModelDebugOptionsComponent to a ModelEntity tells RealityKit to change the way it renders that entity based on a specified visualizationMode. This component isolates individual parts of the rendering process, such as the entity’s transparency or roughness, and displays surface color to help identify visual anomalies.
To use this component, create a ModelDebugOptionsComponent and set its visualizationMode to the desired value. Then, set the component as the entity’s ModelEntity/modelDebugOptions property:
if let robot = anchor.findEntity(named: "Robot") as? ModelEntity {
let component = ModelDebugOptionsComponent(visualizationMode: .normal)
robot.modelDebugOptions = component
}For more information on the visualization modes supported by ModelDebugOptionsComponent, see ModelDebugOptionsComponent.VisualizationMode.
Attach a debug component to an entity
To attach a debug component to a particular entity, traverse the entity tree while passing the component to each child:
// Traverse the entity tree to attach a certain debug mode through components.
func attachDebug(entity: Entity, debug: ModelDebugOptionsComponent) {
entity.components.set(debug)
for child in entity.children {
attachDebug(entity: child, debug: debug)
}
}
// Respond to a button or UI element.
func debugLightingDiffuseButtonCallback() {
let debugComponent = ModelDebugOptionsComponent(
visualizationMode: .lightingDiffuse
)
attachDebug(entity: model, debug: debugComponent)
}Attach a debug component to a trait
To attach a debug component based on a trait, traverse the entity tree while checking for HasModel adoption:
func attachDebug(entity: Entity, debug: ModelDebugOptionsComponent) {
if let model = entity as? ModelEntity {
model.visualizationMode = debug
}
for child in entity.children {
attachDebug(entity: child, debug: debug)
}
}
// Respond to a button or UI element.
func debugLightingDiffuseButtonCallback() {
let debugComponent = ModelDebugOptionsComponent(
visualizationMode: .lightingDiffuse
)
attachDebug(entity: model, debug: debugComponent)
}