I’m trying to figure out how to implement a damage system with the same process and logic across completely different classes, but I’m not sure what the best way to go about it is.
These damage systems aren’t just formulas, they’re literal systems that use delays, resistances, and more.
Actor components seemed like the best way to implement this, but this became unusable as we needed a similar system for part damage in Actor components.
Building a system in an external location such as a Game Instance makes it difficult to reference local variables.
In summary, i want the variables to be local, but their usage to be common throughout. Does anyone know a good way?
All actor already have this implemented. Use the common event AnyDamage to communicate damage between actors.
Use Components to handle your damage in the actors themselves. One component can keep track of damage for multiple “parts”.
Split your logic in specific responsibilities. Damage should always be be only math!
Your ability system should handle delays, timing, animation, cooldowns and delivery of that damage.
If you are unsure on how an ability systems are implemented, check GAS (Gameplay Ability System) that is used in Fortnite.
Happy coding!
P.S.
These systems are usually very big and complex so start small and simple. First deliver damage between two actors. Then handle it clumsily. Then make systems (abilities, weapons) that deliver it. Then refine them little by little. Make your steps incremental because otherwise you quickly loose track of the whole thing.
The damage event is essentially an interface, so it just sends a value. The question is, what do i do next?
Where should i put calculations that i want to share between different classes? It’s easy to access actor components from an actor, but difficult to access components from a component.
If i include a calculation formula in an actor, it will not be accessible to actors of other classes.
It is also necessary to standardize the processing of parameters such as resistance whether they are included in an actor or a component.
These are the details of the problem I’m facing. Where should i start?
I think you are overthinking it in terms of extensibility.
Your characters should derive from a common parent (MyCharacter for example) that handles the damage. I would suggest you put your parameters (resistance, armor, health) in a component but make the calculation in you character class itself accessing all its components directly. After all this Actor is a Your Character exactly because it has those components.
If you want to reuse that formula for another class you either derive from Your Character and all the functionality is already there or you move this function in a function library from where you can reuse it. I don’t expect you to need the library though as scenery and characters usually handle damage very differently. (candle sticks usually lack armor) I mostly move things to a function library if I imagine I would replace those functions with C++ code at some point.
I find Managers cumbersome and unnecessary in such cases but they are an option indeed.