Skip to content

Engine.getEntitiesFor(Family) returning non-matching entities #214

@Barryrowe

Description

@Barryrowe

I've been working with Ashley 1.7.0 for a while and it's been running smooth. I just upgraded to 1.7.2 and now I am getting a NullPointer in the code below. When I get the FollowerComponent from an entity in the list of engine.getEntitiesFor(Family.all(FollowerComponent.class).get()), the FollowerCompnent is null.

This shouldn't be possible correct? All of the entities in the returned array should be guaranteed to have the component's required by the Family.

 EntityListener el;
    @Override
    public void addedToEngine(Engine engine) {
        super.addedToEngine(engine);

        final Engine eg = engine;
        if(el == null){
            el = new EntityListener() {
                private ComponentMapper<FollowerComponent> fm = ComponentMapper.getFor(FollowerComponent.class);

                public void entityAdded(Entity entity) {

                }

                @Override
                public void entityRemoved(Entity entity) {
                    for (Entity follower : eg.getEntitiesFor(Family.all(FollowerComponent.class).get())) {
                        FollowerComponent fc = fm.get(follower);
                       if (fc.target == entity) {  ///<<<<------ error occurs here
                            fc.target = null;
                            follower.removeAll();
                            eg.removeEntity(follower);
                        }
                    }

                }
            };
        }

        engine.addEntityListener(Family.all(EnemyComponent.class).get(), el);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions