- Home /
ECS Buff/Debuff system
Modifier = Buff/Debuff
I'm currently jumping ship with my project from OOP to ECS. And want to change the old abstract decorate pattern to a new faster ECS one.
How the current system works: Base abstract class Modifier
has an Update function that the modifiers use to update their timers/apply over time effects, etc. And there's simple modifier classes like AttackSpeedModifier
that implement Modifier
and only care about the values they use & how they use them. Like this:
protected override void ApplyEffect()
{
Target.AttackSpeed += Value;
}
I'm struggeling to find a proper ECS buff/debuff implementation with only using structs (value types). My current thoughts/approach are such:
1.Make a seperate component for each buff:
public struct ExampleFireAttackBuff : IComponentData
{
public float Damage;
public float Cooldown;
}
The problem with this approach is that every modifier would need its own seperate system, & that would produce a lot of code duplication. And removing component every time the effect is done is also less than ideal.
2.Or make a buffer of buff/debuffs and have a "master" element:
public struct ModifierElement : IBufferElementData
{
public ModifierType ModifierType;
public float Value1;
public float Value2;
public float Value3;
public float Duration;
public bool IsStackable;
etc...
}
The problem with the second approach is that I would need to implement functionality based on "ModifierType" or some other way. Instead of overriding base class. And there would be a lot of redundant data. A simple permanent speed buff would only use 3-4 variables, while the close struct would have much more because all other modifiers need them.
Am I missing something, and/or is there a better way of making such an elaborate system? I'm not really happy with either of them currently. There's also a "ComboModifier" that triggers on specific sets of modifiers, but that's a topic for another day/another thought.
Edit: title got bugged out