#Efficiently query bundle components

6 messages · Page 1 of 1 (latest)

narrow cloud
#

Hi all, I am fairly new to Bevy and the ECS concept. The challenge I am thinking about now is the efficiency querying components that belong to a bundle. As an example, say I have a "CityBundle" that looks like this:

pub struct CityBundle {
    _c: City,
    pub name: CityName,
    pub demographics: Demographics,
    pub resources: Resources,
    ...
}

I have systems that run on the Demographics and Resources components for simulation. However, if I want to create a pop-up window with information about this city, I find myself writing queries of the like:

selection_query: Query<(&CityName, &Demographics, &Resources, &mut Selection), With<City>>

which I can pass to a GUI to display information. However, this feels pretty inefficient especially as what constitutes a CityBundle gets more complex. Is there a better way that I don't know about to avoid complex queries such as these? I am trying to keep the components as simple as possible, but this feels like it comes at the cost of complex queries if I want a bunch of them.

#

Previously, I had a City component that held all of this, but that felt too object oriented...

torn glacier
#

Depending on the complexity you can create type aliases for your common queries

#

Otherwise, another really good approach is to create a custom WorldQuery

narrow cloud
#

Thank you! I made a WorldQuery easy enough, but I have to read a bit about type aliases.