---
title: QueryPredicate
framework: realitykit
role: symbol
role_heading: Structure
path: realitykit/querypredicate
---

# QueryPredicate

An object that defines the criteria for an entity query.

## Declaration

```swift
struct QueryPredicate<Value>
```

## Mentioned in

Implementing systems for entities in a scene

## Overview

Overview Query predicates specify the entities an 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. let modelPredicate = QueryPredicate.has(ModelComponent.self) Create compound predicates You can combine predicates using Swift’s logical operators to create compound predicates. 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: 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. let multiPredicate: QueryPredicate<Entity> =     .has(ModelComponent.self) && .has(PhysicsBodyComponent.self) ||     .has(AnchorComponent.self)

## Topics

### Creating predicates

- [has(_:)](realitykit/querypredicate/has(_:).md)

### Comparing predicates

- [!(_:)](realitykit/!(_:).md)
- [&&(_:_:)](realitykit/&&(_:_:).md)
- [||(_:_:)](realitykit/__(_:_:).md)

## See Also

### Entity searches

- [PixelCastHit](realitykit/pixelcasthit.md)
