Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.

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

Open
Apjue opened this issue Jul 4, 2016 · 3 comments
Open

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

Apjue opened this issue Jul 4, 2016 · 3 comments

Comments

@Apjue
Copy link

Apjue commented Jul 4, 2016

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.

@miguelmartin75
Copy link
Owner

Call e.activate()

@Apjue
Copy link
Author

Apjue commented Jul 5, 2016

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 ?

@miguelmartin75
Copy link
Owner

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants