Skip to content
Flecs v4.1
entities/multi_set_get

  • C++

    View on GitHub

    1#include <multi_set_get.h>
    2#include <iostream>
    3
    4/* This code shows how to get & set multiple components in a single command */
    5
    6struct Position {
    7 double x, y;
    8};
    9
    10struct Mass {
    11 double value;
    12};
    13
    14int main(int, char *[]) {
    15 flecs::world ecs;
    16
    17 // Create new entity, set Position and Mass component
    18 flecs::entity e = ecs.entity()
    19 .insert([](Position& p, Mass& m) {
    20 p.x = 10;
    21 p.y = 20;
    22 m.value = 100;
    23 });
    24
    25 // Print values of Position and Mass component
    26 bool found = e.get([](const Position& p, const Mass& m) {
    27 std::cout << "Position: {" << p.x << ", " << p.y << "}\n"
    28 << "Mass: {" << m.value << "}\n";
    29 });
    30
    31 std::cout << "Components found: " << (found ? "true" : "false") << "\n";
    32
    33 // Output:
    34 // Position: {10, 20}
    35 // Mass: {100}
    36 // Components found: true
    37
    38 return 0;
    39}
    flecs::entity entity(Args &&... args) const
    Create an entity.
    Definition impl.hpp:195
    const Self & insert(const Func &func) const
    Set 1..N components.
    Definition impl.hpp:23
    Entity.
    Definition entity.hpp:30
    The world.
    Definition world.hpp:129