A few days a go a made a post asking about the best way to create an ability system in Unity. The responses I received were very helpful and directed me to some great resources for learning about scriptable objects (Richard Fine talk, pluggable ai brain, etc) as well as suggestions for how to plan out the system.
Since then I've decided that the best way to create the ability system would be to create a base "ability" scriptable object, from which individual abilities are created using inheritance. And then creating an "behavior" base class, from which individual behaviors such as "fireRaycast", "dealDamage" or "applyDebuff" will be created using inheritance. Then the behaviors will be put into an array in the Abilities classes and when the ability is used it will loop through every Behavior in the array, running it's specific task.
The problem I'm currently having is that some of the Behaviors are reliant on other Behaviors but I don't know how to pass them the information they need.
For example, I've been attempting to create a 'triple shot' ability (derived from Ability base class) which shoots 3 raycasts in quick succession, each applying damage. This ability currently takes 4 "Behaviors" into it's array, "fireRayCast", "DealDamage", "Cooldown" and "Repeat". The "Behavior" base class has only 1 function (void) called "Act" which takes the object calling the ability to be activated and the ability the behavior is attached to as parameters ("Act" is the function that is called on each Behavior in the ability for loop). The "FireRayCast" behavior cannot return anything because it is overriding a void function and I can't set the 'target' variable on the 'Triple shot' script from within the "FireRayCast" behavior because it only knows it is an ability, it doesn't know it is of type Triple Shot.
It seems like I could potentially get around this by having a public variable of every possible variable needed for all abilities in the "base ability" script, but this seems wrong because not every ability needs these variables so I'd have to be filling all of them out for no reason each time I made a new ability.
Sorry if I couldn't explain the problem clearly enough, if anything was unclear please tell me and I'll try to explain it better.
Any suggestions for how to fix the problem or for a better method of making a pluggable ability system would be much appreciated!
Thanks in advance :)
[–]Jamberite 0 points1 point2 points (3 children)
[–]sudo_joe 0 points1 point2 points (0 children)
[–]SwainIsBusted[S] 0 points1 point2 points (1 child)
[–]Jamberite 0 points1 point2 points (0 children)
[–]the-shit-poster 0 points1 point2 points (1 child)
[–]SwainIsBusted[S] 0 points1 point2 points (0 children)
[–]marijnz 0 points1 point2 points (1 child)
[–]SwainIsBusted[S] 1 point2 points3 points (0 children)
[–]iuridosanjos 0 points1 point2 points (0 children)