diff --git a/core/include/cubos/core/ecs/world.hpp b/core/include/cubos/core/ecs/world.hpp index d47f0c94ce..b1197bf089 100644 --- a/core/include/cubos/core/ecs/world.hpp +++ b/core/include/cubos/core/ecs/world.hpp @@ -7,9 +7,9 @@ #include #include -#include #include #include +#include #include #include #include @@ -29,7 +29,8 @@ namespace cubos::core::ecs { public: /// @brief World constructor. - World() { + World() + { this->registerComponent(); } diff --git a/core/tests/ecs/blueprint.cpp b/core/tests/ecs/blueprint.cpp index 72b9815117..7cb5a67d4f 100644 --- a/core/tests/ecs/blueprint.cpp +++ b/core/tests/ecs/blueprint.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "utils.hpp" @@ -10,6 +11,7 @@ using cubos::core::ecs::Blueprint; using cubos::core::ecs::CommandBuffer; using cubos::core::ecs::Commands; using cubos::core::ecs::Entity; +using cubos::core::ecs::Name; using cubos::core::ecs::World; TEST_CASE("ecs::Blueprint") @@ -183,4 +185,28 @@ TEST_CASE("ecs::Blueprint") CHECK(dict.map.at('0') == spawned0); CHECK(dict.map.at('1') == spawned1); } + + SUBCASE("check if entities from spawned blueprint have the right components") + { + Blueprint blueprint{}; + auto entity0 = blueprint.create("0"); + auto entity1 = blueprint.create("1"); + blueprint.add(entity0, IntegerComponent{0}); + blueprint.add(entity1, IntegerComponent{1}); + + // Spawn the blueprint into the world and get the identifiers of the spawned entities. + auto spawned = cmds.spawn(blueprint); + auto spawned0 = spawned.entity("0"); + auto spawned1 = spawned.entity("1"); + cmdBuffer.commit(); + + auto components0 = world.components(spawned0); + auto components1 = world.components(spawned1); + REQUIRE(components0.has()); + REQUIRE(components1.has()); + REQUIRE(components0.has()); + REQUIRE(components1.has()); + CHECK(components0.get().value == 0); + CHECK(components1.get().value == 1); + } }