API reference
API reference
Select your platform
No SDKs available
No versions available

Query

Query

class Query
A query system for finding and filtering entities in the Spatial SDK.
Use the DSL builder pattern with Query.where { ... } to create queries. The query DSL allows you to specify conditions on entities, such as having specific components or having changed components. You can also combine conditions with logical operators (and, or) to create complex queries.
Example - Find all entities with a specific component:
val entities = Query.where { has(Transform.id) }.eval()
Example - Find entities with multiple components:
val entities = Query.where { has(Transform.id, Mesh.id) }.eval()
Example - Find entities with components that have changed in the last tick:
val entities = Query.where { changed(Transform.id) }.eval()
Example - Combining queries with logical operators:
val entities = Query.where { (has(Transform.id) and has(Mesh.id)) or has(Panel.id) }.eval()
Example - Using filters with queries:
val entities = Query.where { has(TestComponent.id) }
                    .filter { by(TestComponent.intVarData).isEqualTo(1) }
                    .eval()
Example - Using sort with queries:
val entities = Query.where { has(TestComponent.id) }
                    .sort {
                      with {
                        by(TestComponent.intVarData)
                      }
                    }.eval()

Types

NameSummary
Companion
object Companion

Properties

NameSummary
prev_
var prev_: Query?
query_
var query_: IntArray

Functions

NameSummary
build
fun build(): BuiltQuery

Evaluates the query for a specific DataModel and returns the a built query.
eval
fun eval(): <Error class: unknown class><Entity>

Evaluates the query and returns a sequence of entities that match the query criteria.



fun eval(dm: DataModel): <Error class: unknown class><Entity>

Evaluates the query against a specific DataModel and returns matching entities.
filter
fun filter(initializer: FilterBuilder.() -> Unit): Query

Specifies the filter criteria for the query.
sort
fun sort(initializer: SortBuilder.() -> Unit): Query

Specifies the sort order for the query.

Companion

object Companion

Functions

NameSummary
eval
fun eval(preBuiltQuery: BuiltQuery): <Error class: unknown class><Entity>

Evaluates a pre-built query and returns a sequence of entities that match the query.



fun eval(dm: DataModel, preBuiltQuery: BuiltQuery): <Error class: unknown class><Entity>

Evaluates a pre-built query on a specific DataModel and returns a sequence of entities that match the query.
where
fun where(initializer: QueryBuilder.() -> Unit): Query

DSL for building queries. The DSL provides an interface for building complex queries with logical operations.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon