Contents

EntityQuery

An object that retrieves entities from a scene.

Declaration

struct EntityQuery

Mentioned in

Overview

Use entity queries to iterate through all entities in a RealityKit scene that meet certain criteria. To specify which entities to retrieve, use a QueryPredicate.

To execute the query, pass it into the scene’s performQuery(_:) method and then iterate over the results.

// Build a query to retrieve all anchor components.
let query = EntityQuery(where: .has(AnchorComponent.self))

// Find and modify the scene's entities that have an anchor component.
scene.performQuery(query).forEach { entity in
    // Make any needed changes to entities.
}

Topics

Creating an entity query

See Also

Entity queries