anax icon indicating copy to clipboard operation
anax copied to clipboard

[Bug ?] getEntities() does not return any entity

Open Apjue opened this issue 8 years ago • 3 comments

Hello, My system doesn't get any entity with getEntities(): class AISystem : public anax::System<anax::Requires<Components::Path, Components::Position, Components::MoveTo>> In update(): auto entities = getEntities(); So, I have a function which create a character. ` inline anax::Entity make_character(anax::World& w, ...) { anax::Entity e = w.createEntity();

e.addComponent<Components::GraphicsItem>(...);

e.addComponent<Components::Life>(...);
e.addComponent<Components::Fight>();

e.addComponent<Components::Direction>(...);
e.addComponent<Components::Position>();
e.addComponent<Components::MoveTo>();
e.addComponent<Components::Path>();

e.addComponent<Components::Animation>(...);

w.refresh();
return e;

} And I use this in my "main" class: //... m_char = make_character(...); m_char.activate(); m_world.refresh(); ` And I use AISystem::update() in the event loop. But the vector of entities is always empty... Why ? Thanks.

Apjue avatar Jul 04 '16 18:07 Apjue

Call e.activate()

miguelmartin75 avatar Jul 05 '16 01:07 miguelmartin75

I saw the problem ! (it wasn't activate()) When adding the system to the world after creating and entity and adding the components to it, the system doesn't detect the entity... I have to add the system before creating the entity So... it is a bug right ?

Apjue avatar Jul 05 '16 11:07 Apjue

When you call world.refresh() it will notify all the systems you have attached currently, i.e. the systems getEntities() attribute will hold the invariant that they contain the appropriate entities. Any system not currently added will not work.

The only solution that I can think of to "resolve" this is either:

  1. Add the systems beforehand
  2. Change the implementation to query the entities each time a call to getEntities() is made

miguelmartin75 avatar Jul 05 '16 12:07 miguelmartin75