Suppose I have a system which computes a list of all entities which are colliding this frame. Then, I have some systems which use these collisions (e.g. computing damage / velocity). What's the fastest way for these systems to communicate? I can currently think of either piping something like a Vec<(Entity, Entity)> between systems or using an Event(Entity, Entity).
#system piping vs events
1 messages · Page 1 of 1 (latest)
Could you build both of those options then benchmark them?
yea i probably should do that if i care about performance
i was just wondering if anyone here who's familiar with the bevy architecture would definitively know the answer so I wouldn't need to do that 😛
I did the same thing with pipes. Here: https://discord.com/channels/691052431525675048/1266719678621941812
But on retrospect, I think events are way more ergonomic
Piping sort of creates a "bigger system" that runs at once, as far as I understand. But Events will be much better for your use case IMO since most communication between systems is resolved with them. It also lets you send and read events from anywhere, thus letting you have X amount of senders and a single reader for example (which makes things easier and you don't need to pipe your collision systems everywhere). Just be aware that you might need some ordering of the systems (either via system sets or schedules) so senders run before readers.
In terms of performance, it always depends. But if you have several sender systems and several reader systems that do different work over the collisions (e.g. spawn particles, prevent movement and then add forces) I feel like it would be much more performant to have them run in parallel, which you can't really do with piping.
And finally, worrying too early about performance tends to come from the voices of the little devil in our shoulder 😆