Is there a way to get an EntitySet that does NOT contain a component?

So im rewriting some of my code trying to make it less cumbersome. I keep running into a situation where I would need less components attached to objects in general if I could have a filter that excludes entities with certain components. One situation is:

I have a series of stage elements with colliding hitboxes, however some of these stage elements can save an entity in an ArrayList. This is for things such as a moving platform, so it can move other entities that are resting on top along with it when it moves. something that can be “grounded” will check if it is on top of a normal stage element (so it can do something like jump), but also check with if it is grounded on something that can save entities.

The problem is I do not want to do the check Twice.

    this.stationarySet = ed.getEntities(RectCollider.class, Stage.class);
    
    this.attachedSet = ed.getEntities(RectCollider.class,
            Attached.class);

I would like to mention in stationarySet that I do notthings with an Attached.class

No, this is kind of a hard question to answer also in the general case because of how events are propagated. There is generally a way to structure code such that it isn’t really need… like it would be convenient a little bit but technically the other way is more right.

I would need to know more about what RectCollider and Attached and Stage are.

ahh ok. Well in this case RectCollider just holds a rectangle (width, height, angle etc…) and Stage is just a tag literally nothing in it, and Attached is a list of Entities that are “attached” to an entitiy so it can be moved by it later. StationarySet is like normal stage elements, attachedSet are stage elements that save entities so they can be moved when they do.

In general I seem to be running into this “classification” problem. Usually I have a set of objects that fit the domain of a AbstractGamSystem like a “grounded” system, but there are usually objects that meet those requirements also that dont belong. I really wanted to avoid tagging items with strings or empty components since I feel like the whole point of of an ECS was being able to share concepts among objects and tagging would make the game systems very specific. But it is what I ended up doing.

EDIT: in the end it seems the best solutions are:
a) make things a little more specific by tagging them.
b) accept slight repition in some calculations (which does make things quite clean however)

Since I don’t have a clear understanding of what these are being used for (sorry), it could also be that you have multiple systems where they really should be one… and/or that you are using components to communicate things that don’t need to be communicated.

That sounds really weird to me. Components that contain lists of entities?

Sounds like a follow-system or link-system but I would do the other way around. So for example if you have an space ship entity and 3 orbiting helpers which should follow the spaceship I would not have a component with a list of entities but do it the other way around the orbiting helper have a link-component which point to the spaceship.

But maybe you have something completly different than what I mean, then just ignore my advice.

1 Like