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
Answered
by
SanderMertens
TypeDefinition
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
SanderMertens
Jan 23, 2023
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.
1 reply
Answer selected by
TypeDefinition
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 …