Skip to content
Flecs v4.1
queries/find_entity

  • C++

    View on GitHub

    1#include <find_entity.h>
    2#include <iostream>
    3
    4struct Position {
    5 int x, y;
    6};
    7
    8int main() {
    9 flecs::world ecs;
    10
    11 ecs.entity("e1").set<Position>({10, 20});
    12 ecs.entity("e2").set<Position>({20, 30});
    13
    14 // Create a simple query for component Position
    15 flecs::query<Position> q = ecs.query<Position>();
    16
    17 // Find the entity for which Position.x is 20
    18 flecs::entity e = q.find([](Position& p) {
    19 return p.x == 20;
    20 });
    21
    22 if (e) {
    23 std::cout << "Found entity " << e.path() << std::endl;
    24 } else {
    25 std::cout << "No entity found" << std::endl;
    26 }
    27
    28 // Output
    29 // Found entity ::e2
    30}
    conditional_t< sizeof...(Args)==0 &&_::is_sparse_query< Comps... >::value, flecs::sparse_query< Comps... >, flecs::query< Comps... > > query(Args &&... args) const
    Create a query.
    Definition impl.hpp:326
    flecs::entity entity(Args &&... args) const
    Create an entity.
    Definition impl.hpp:195
    Entity.
    Definition entity.hpp:30
    Typed query.
    Definition impl.hpp:271
    The world.
    Definition world.hpp:129