Timeline for Is it better design to store event effects within an Entity itself, or within a system?
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 17, 2021 at 14:32 | comment | added | Philipp | Let us continue this discussion in chat. | |
| Jun 17, 2021 at 14:32 | comment | added | Ryan Peschel | Yeah, I originally had something like that as well, but I'm not sure how scalable it is, no? Like for example, if you want to do more complex things when different entities collide, then what? For example, if you had a bear trap entity that should apply a slowing debuff and deal damage, or a healing totem, then what? Do you just create a marker component for every single different type of entity? Like, have a BearTrapComponent, a FireTrapComponent, an IceTrapComponent, etc.? | |
| Jun 17, 2021 at 14:32 | comment | added | Philipp | Or even better: Have the events carry the involved components, not the entities: event.hurtbox.hp -= event.hurtbox.damage | |
| Jun 17, 2021 at 14:26 | comment | added | Philipp | if( (HasComponent(event.entity1, HurtBox) && HasComponent(event.entity2, HitBox) ) { /* apply damage */ } | |
| Jun 17, 2021 at 14:24 | history | edited | Philipp | CC BY-SA 4.0 | deleted 1 character in body |
| Jun 17, 2021 at 14:19 | comment | added | Philipp | @RyanPeschel Yes, I would go with the second one. Although I would not use entity types in the events. I would not decide what to do based on event.entity1 is bullet and event.entity2 is player. I would decide based on the components those entities have. | |
| Jun 17, 2021 at 14:17 | history | edited | Philipp | CC BY-SA 4.0 | added 194 characters in body |
| Jun 17, 2021 at 14:17 | comment | added | Ryan Peschel | So are you saying I should go with option 2 in my original post, or something slightly different? | |
| Jun 17, 2021 at 14:15 | comment | added | Philipp | @RyanPeschel Ah, I see. Answer updated. ECS should not have any executable code in components, so the code which gets executed on an event should be part of a system. Yes, I know that JavaScript makes it really easy to attach small snippets of code to objects in form of lambda expressions. But that's not how ECS is supposed to work. | |
| Jun 17, 2021 at 14:14 | history | edited | Philipp | CC BY-SA 4.0 | added 194 characters in body |
| Jun 17, 2021 at 14:13 | comment | added | Ryan Peschel | Right, I'm using an archetype-based ECS (so iteration is cheap but adding/removing components is expensive), so I have already created an event queue for my project. I think I may have miscommunicated, as I'm not really asking about whether to use an event queue vs components as events, but rather whether to store event handlers within components or within systems. | |
| Jun 17, 2021 at 14:08 | history | answered | Philipp | CC BY-SA 4.0 |