skypjack / entt

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more
https://github.com/skypjack/entt/wiki
MIT License
9.6k stars 844 forks source link

Is there a way to retrieve a view with at least one of the specified components? #1084

Closed kewyj closed 7 months ago

kewyj commented 7 months ago

I am looking through the crash course, and the one thing I found closest to what I need is a view pack. Would this work? Also curious about how EnTT works with components with inheritance. Would registry.view<base>(); yield all entities containing base/derived components?

skypjack commented 7 months ago

Is there a way to retrieve a view with at least one of the specified components?

What does it mean a view with at least one of the specified components? As if it were an or rather than an and?

Would registry.view(); yield all entities containing base/derived components?

Definitely no. Stop thinking in terms of hierarchies when it comes to using an ECS model.

kewyj commented 7 months ago

As if it were an or rather than an and?

Yes exactly that!

skypjack commented 7 months ago

Then no, I'm sorry. Views return only the entities that have all the elements. If you want those that have at least one of components and you want them only once, probably the best is to iterate multiple views separately and put the entities in a set. However, this really, really, really smells of an XY-problem. Something like I have states idle and jump and I want to find the entities that have a state, no matter what. Just rethink your design. You don't need an or-like view here. You just need to refactor your component types and probably a more ECS-y thinking. 👍

kewyj commented 7 months ago

Hmm, ok! I'll try to rethink my approach. Thanks so much!