libgdx/ashley

Is it possible to get entities by their common interface?

Closed this issue · 4 comments

xahon commented
interface IMyComponentBase implements Component {}

class Derived1 implements IMyComponentBase {}
class Derived2 implements IMyComponentBase {}

engine.getEntitiesFor(
    Family.all(IMyComponentBase.class).get() // not working
);

I have this problem too, It only returns the first entity that matches the specified family.

@xahon you can't do that, components are registered by its concrete class.
and what you want to do is against ECS principle IMO.

xahon commented

@mgsx-dev may be you're right. I still haven't stopped thinking in OOP style but right now I can't give you an example for this problem

I'm a bit late to the party, but maybe you will find it useful. Family is a powerful tool, you still can put all required component classes manually under any rule and get pretty the same result. If you prefer, a bit of automation could be achieved with reflection.