-
Coming from some other modern ECS libraries, I am quite used to being able to use the query API (or something similar) to specify exactly what kind of entities I want to receive in my event handlers. Is there a way to do this natively in FrifloECS? I see OnComponentAdded / Removed, as well as the equivalent for tags, however, those have no restrictions on what components you will be querying. So, I looked to EventFilters, but looking at the source code, it seems like the EventFilter will return true if any of the component / tag filters are matched, without much room for actual query-building. Is the intended way to receive only specific events to manually check if the relevant entity has (or doesn't have) the set of components / tags that I want by using HasComponent and Tags.Has after I've already received the event callback? It seemed wasteful to iterate over all the entities in a query just to return if it doesn't match the filter, but maybe that's where I am mistaken, and that's the superior option when compared to trying to use the event callbacks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
hi @Danon5,
The intension for
world.OnComponentAdded += change => {
if (change.ComponentType.Type == typeof(Component1)) {
...
}
};
Correct, that is the intended way to process component / tag events.
If there a many events to process for each the query approach will be more performant. |
Beta Was this translation helpful? Give feedback.
hi @Danon5,
The intension for
OnComponentAdded
/OnComponentAdded
is to avoid adding / removing event handlers for each component type. The assumption is that the handler will execute the same code independent from the specific added / removed component type.ComponentType.Type
can be used to handl…