<!--
{
  "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/QueryPredicate",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation14QueryPredicateV"
  },
  "title" : "QueryPredicate"
}
-->

# QueryPredicate

An object that defines the criteria for an entity query.

```
struct QueryPredicate<Value>
```

## Overview

Query predicates specify the entities an [`EntityQuery`](/documentation/RealityKit/EntityQuery) returns from a
scene. Predicates describe entities based on which components they contain,
or on the entity’s relationship to other entities in the scene. For example,
you can build a predicate to retrieve the model entities from a scene.

```swift
let modelPredicate = QueryPredicate.has(ModelComponent.self)
```

### Create compound predicates

You can combine predicates using Swift’s logical operators to create
compound predicates. [`QueryPredicate`](/documentation/RealityKit/QueryPredicate) supports Swift’s logical `AND`
(`&&`), logical `OR` (`||`), and logical `NOT` (`!`) operators. The
following code shows how to build a compound predicate that returns all
entities that are either model entities or anchor entities:

```swift
let orPredicate: QueryPredicate<Entity> =
    .has(ModelComponent.self) || .has(AnchorComponent.self)
```

Use parentheses to control the order of operations when combining
predicates. For example, you can create a query that returns any entity that
has both a model component and a physics body component, or any entity that
has only an anchor component.

```swift
let multiPredicate: QueryPredicate<Entity> =
    .has(ModelComponent.self) && .has(PhysicsBodyComponent.self) ||
    .has(AnchorComponent.self)
```

## Topics

### Creating predicates

[`has(_:)`](/documentation/RealityKit/QueryPredicate/has(_:))

Creates a new predicate that describes entities that have a specific
component.

### Comparing predicates

[`!(_:)`](/documentation/RealityKit/!(_:))

Returns a predicate which evaluates to `true` if `operand` evaluates to `false`.

[`&&(_:_:)`](/documentation/RealityKit/&&(_:_:))

Returns a predicate which evaluates to `true` if `left` AND `right` evaluate to `true`.

[`||(_:_:)`](/documentation/RealityKit/__(_:_:))

Returns a predicate which evaluates to `true` if `left` OR `right` evaluates to `true`.



---

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)