Abilities are complicated when first created, but once you understand how it all runs you will get the hang of it. Abilities use Scriptable Objects (SO), which essentially is a container that holds all the data the ability needs. To create a new ability:
- Create a new ability SO. Go to Assets → Asset Identifier SOs → Abilities → Enemy OR Player → {Unit Name}. Right click inside the folder, and on the popup go to Create → Ability → Ability Definition. Name it whatever the ability is called. Inside the inspector of the ability definition, click the three dots on the right of the SO name (up in the top right), and click “Generate new GUID”. A GUID is a unique identifier that many things use within the game use.
- Fill out the SO with all available information (don’t worry about Ability Effect Configs, we will get to them shortly. You also wont need to change anything with the Animation Data).
- Add the ability effects. Ability Effect Configs are essentially the actions the ability will take. For example, if an ability does 20 damage to an enemy, you will add a damage config. This was done so that we could shorten creation time and reuse actions where possible. You can add as many effect configs as needed, so if you have an ability that attacks 3 times, add 3 damage effects. Try to reuse configs if at all possible, I will go over creating new ones later if one doesn’t exist that matches what you need. To add the Ability Effects Configs: ^54aecc
- Click the plus sign at the bottom of the Ability Effect Configs box.
- Attach the effect SO. They should be named after what they do (e.g. heal effect, damage effect). Admittedly, an audit needs to be done so that all names match, but for now you should be able to find an effect that you need (if it already exists). The effect is what controls what the ability action will do. E.g. the damage effect will do damage.
- Attach a condition if needed. If your ability only works under certain conditions, this is where they are checked. For example, if your ability only activates if the source of the ability has less than 50% health, then you would add a condition that prevents the ability from happening if the unit is above that threshold. For the most part, abilities won’t have conditions. If they do, feel free to reach out and I’ll explain it more in depth.
- Select the Effect Parameters. The parameters is the data that the effect SO uses. For the most part, the effect parameters should be named after the effect. So for example, if you have the DamageEffect selected as the effectSO, choose the DamageEffectParameters. Once you have chosen the parameters, fill out the data.
- If no effect SO exists that does what your ability needs to do, you can make a new effect. To do so:
- Go to Assets → Scripts → Ability System → Effects. Create a new monobehavior script and call it “Ability{whatever the ability does}Effect”. Inside the new script, make it inherit from AbilityEffect. Above the declaration of the class (public class Ability{Effect}Effect : AbilityEffect), you will need to make a reference to this SO in the asset menu. This lets you create the SO in the project. Copy and paste this from another ability effect, and change the fileName and menuName.
- Before being able to create the ability effect logic, you need to make the parameters. Inside EffectParameters.cs, create a new parameter. Follow existing parameters for guidance. Essentially whatever variables your ability will need, put them in the parameters. Once created, go back to the effect script and make a reference to the parameters.
- For the logic, I’d advise following along with the DamageEffect script as it is the most barebones an effect can be, and will help get you started. Essentially you want to override the base scripts initialize so that you can set the parameters. You should be able to just copy and paste it from the DamageEffect script and change the naming where needed. You should also delete the start and update functions, and replace them with the Execute function (again you can copy and paste it from the DamageEffect script or generate it from the quick actions by right clicking on the class name). Again follow what exists already in other scripts as a guideline and alter/add where needed.
- Once the logic for the effect is finished, go back into the project. Go to Assets → Ability Effects and create the SO. Do this by right clicking in the folder, going to Create → Ability → Ability Effects → {The effect you just made}. Now you should be able to add this effect to your ability.
And that’s it for abilities. You can then attach these to the BaseUnit prefabs.