Why is it okay to have a system that takes a entity and a const component, but not okay to take an entity and non-const component? #916
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
My guess is that The reason for this is that empty types are not actually stored by the ECS, and if they are part of a system/query signature a temporary object of the empty type is created to pass to the The reason this works with const but not for non-const, is that while C++ does let you pass a temporary object to a Since an empty type can't actually store values, a cleaner way is sometimes to use world.system("Move")
.with<root>()
.each([](flecs::entity e) { // component passed by `with` doesn't become part of signature
}); Hope that helps! |
Beta Was this translation helpful? Give feedback.
My guess is that
root
is an empty type, and empty types are passed by value (tryroot p
).The reason for this is that empty types are not actually stored by the ECS, and if they are part of a system/query signature a temporary object of the empty type is created to pass to the
each
function.The reason this works with const but not for non-const, is that while C++ does let you pass a temporary object to a
const T&
, you can't pass a temporary object to aT&
.Since an empty type can't actually store values, a cleaner way is sometimes to use
with
:Hope that …