anax
anax copied to clipboard
[Bug ?] getEntities() does not return any entity
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.
Call e.activate()
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 ?
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:
- Add the systems beforehand
- Change the implementation to query the entities each time a call to
getEntities()
is made