Closed kewyj closed 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.
As if it were an or rather than an and?
Yes exactly that!
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. 👍
Hmm, ok! I'll try to rethink my approach. Thanks so much!
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?