<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/EntityQuery",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation11EntityQueryV"
  },
  "title" : "EntityQuery"
}
-->

# EntityQuery

An object that retrieves entities from a scene.

```
struct EntityQuery
```

## 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`](/documentation/RealityKit/QueryPredicate).

To execute the query, pass it into the scene’s [`performQuery(_:)`](/documentation/RealityKit/Scene/performQuery(_:))
method and then iterate over the results.

```swift
// 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

[`init()`](/documentation/RealityKit/EntityQuery/init())

Creates a query that returns all entities in a scene.

[`init(where:)`](/documentation/RealityKit/EntityQuery/init(where:))

Creates a query that returns all entities in a scene that match specific
criteria.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)