Skip to content

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

Discussion options

You must be logged in to vote

My guess is that root is an empty type, and empty types are passed by value (try root 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 a T&.

Since an empty type can't actually store values, a cleaner way is sometimes to use with:

world.system("Move")
  .with<root>()
  .each([](flecs::entity e) { // component passed by `with` doesn't become part of signature
  });

Hope that …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TypeDefinition
Comment options

Answer selected by TypeDefinition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants