# Flexible ability system

**URL:** https://discussions.unity.com/t/flexible-ability-system/932205
**Category:** Scripting
**Tags:** Scripting, Question
**Created:** [October 28, 2023, 11:00pm UTC](https://discussions.unity.com/t/flexible-ability-system/932205 "2023-10-28T23:00:25Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![WillyDev01](https://avatars.discourse-cdn.com/v4/letter/w/779978/32.png) [@WillyDev01](https://discussions.unity.com/u/WillyDev01)
#### Post date: [October 28, 2023, 11:00pm UTC](https://discussions.unity.com/t/flexible-ability-system/932205/1 "2023-10-28T23:00:25Z")

</div>

I am trying to implement aflexible ability system for my game. I have multiple different playable Character, and they each need to have their own collection of different abilities. The current setup i have for Abilities is as follow :  
**AbilityBase : ScriptableObject** :  
This contains all basic infos related to each ability, such as cooldown, type, icon sprite, etc…

**abstract Ability: Monobehaviour** :  
This is an abstract class that contains code for common behaviour across all abilities, such as cooldown changes, and an abstract Activate method that each different ability script will override with their own code. This script also has an AbilityBase variable.

**AbilityName : Ability**  
Finally, i have multiple different ability scripts, each inheriting from the abstact ability class and implementing their own Activate method.

The problem i am running into with this structure is that in the editor, i cannot put individual abilities in my character’s ability collections. In my character script i have a public List, But the editor does not let me put my individual ability scripts inheriting from **Ability** in that list. I am a bit lost on how to achieve this system.

Thanks !

---

<div class="post-metadata">

### Author: ![spiney199](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/spiney199/32/880897_2.png) [@spiney199](https://discussions.unity.com/u/spiney199)
#### Post date: [October 29, 2023, 12:31am UTC](https://discussions.unity.com/t/flexible-ability-system/932205/2 "2023-10-29T00:31:28Z")

</div>

> [@WillyDev01](#):
>
> The problem i am running into with this structure is that in the editor, i cannot put individual abilities in my character’s ability collections. In my character script i have a public List, But the editor does not let me put my individual ability scripts inheriting from **Ability** in that list. I am a bit lost on how to achieve this system.

Are you trying to drag in the script assets? They’re just text files.

You’d need to drag in a component instance in a scene, or one that is on the root game object of a prefab.

---

<div class="post-metadata">

### Author: ![Kurt-Dekker](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kurt-dekker/32/101578_2.png) [@Kurt-Dekker](https://discussions.unity.com/u/Kurt-Dekker)
#### Post date: [October 29, 2023, 2:21pm UTC](https://discussions.unity.com/t/flexible-ability-system/932205/3 "2023-10-29T14:21:25Z")

</div>

There may be some handy nuggest in this:

ScriptableObject usage in RPGs:

> [@ScriptableObjects for an RPG with multiple units in your team](https://discussions.unity.com/t/798767/2):
>
> The most important concept about ScriptableObjects (SOs) is that they are custom-shaped blobs of data that you can edit inside the Unity inspector. The serialized values inside a SO map directly to that created asset on disk, the instance of the SO. When your game runs, it needs some data. One way to get that data is to hard-code it in the code. That is bad because when you change it, you need to change code. That's why we have things like a SO to configure existing unchanging…

> [@Creating lookup tables that can be assigned in the inspector.](https://discussions.unity.com/t/803356/2):
>
> This looks like a job tailor made for ScriptableObjects! ScriptableObjects are basically structured blobs of predefined data to help you create content for your game. For instance if I had a ScriptableObject called Weapon, it might have these properties: name detailed name description damage toughness weight what it looks like in the inventory what model it uses in game what animations the player uses to swing it I would create many of these Weapons, each one a file on disk (also called an…

Usage as a shared common data container:

[![](https://europe1.discourse-cdn.com/unity/original/4X/1/d/9/1d9d846ee63fa8118da40bc3481f688622bfbfcd.jpeg "Better Data with Scriptable Objects in Unity! (Tutorial)") ](https://www.youtube.com/watch?v=PVOVIxNxxeQ)

---

<div class="post-metadata">

### Author: ![WillyDev01](https://avatars.discourse-cdn.com/v4/letter/w/779978/32.png) [@WillyDev01](https://discussions.unity.com/u/WillyDev01)
#### Post date: [October 30, 2023, 8:39pm UTC](https://discussions.unity.com/t/flexible-ability-system/932205/4 "2023-10-30T20:39:25Z")

</div>

> [@spiney199](#):
>
> Are you trying to drag in the script assets? They’re just text files.
> 
> You’d need to drag in a component instance in a scene, or one that is on the root game object of a prefab.

I didn’t think about instantiating every Ability script in the editor. However, since every ability can only be assigned to one character, and there might be many many abilities, It could create a lot of additionnal clutter in my scene. Is this common/good practice ?

---

<div class="post-metadata">

### Author: ![spiney199](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/spiney199/32/880897_2.png) [@spiney199](https://discussions.unity.com/u/spiney199)
#### Post date: [October 30, 2023, 10:11pm UTC](https://discussions.unity.com/t/flexible-ability-system/932205/5 "2023-10-30T22:11:01Z")

</div>

> [@WillyDev01](#):
>
> I didn’t think about instantiating every Ability script in the editor. However, since every ability can only be assigned to one character, and there might be many many abilities, It could create a lot of additionnal clutter in my scene. Is this common/good practice ?

Honestly none of this stuff should live in scenes. I would keep all the data pertaining to abilities to scriptable object asset land, and then these scriptable objects can be used to define the abilities of any given character.

If they need to have state that gets updated during gameplay, then the scriptable objects can act as a factory for some kind of runtime instance.

---

<div class="post-metadata">

### Author: ![WillyDev01](https://avatars.discourse-cdn.com/v4/letter/w/779978/32.png) [@WillyDev01](https://discussions.unity.com/u/WillyDev01)
#### Post date: [November 2, 2023, 4:53pm UTC](https://discussions.unity.com/t/flexible-ability-system/932205/6 "2023-11-02T16:53:39Z")

</div>

> [@Kurt-Dekker](#):
>
> There may be some handy nuggest in this:
> 
> ScriptableObject usage in RPGs:
> 
> [https://discussions.unity.com/t/798767/2](https://discussions.unity.com/t/798767/2)
> 
> [https://discussions.unity.com/t/803356/2](https://discussions.unity.com/t/803356/2)
> 
> Usage as a shared common data container:
> 
> [https://www.youtube.com/watch?v=PVOVIxNxxeQ](https://www.youtube.com/watch?v=PVOVIxNxxeQ)

My current usage of scriptable objects seems to be in line with what this suggests. My problem mostly lies in how each character should store their abilties monobehaviors. Each ability has it’s own runtime script, I just dont know how to make a nice generalized, decoupled way of storing multiple abilities in one Character, without having to hardcode which ability goes on which character

---

<div class="post-metadata">

### Author: ![qbvbsite](https://avatars.discourse-cdn.com/v4/letter/q/97f17d/32.png) [@qbvbsite](https://discussions.unity.com/u/qbvbsite)
#### Post date: [November 2, 2023, 5:37pm UTC](https://discussions.unity.com/t/flexible-ability-system/932205/7 "2023-11-02T17:37:55Z")

</div>

> [@WillyDev01](#):
>
> My current usage of scriptable objects seems to be in line with what this suggests. My problem mostly lies in how each character should store their abilties monobehaviors. Each ability has it’s own runtime script, I just dont know how to make a nice generalized, decoupled way of storing multiple abilities in one Character, without having to hardcode which ability goes on which character

Personally, I would just have Abilities as C# classes with properties and logic functions. Then on your character script (the one attached to the model) had a List (or a dictionary that you could use an AbilityType enum to find a specific ability). That would be used store them and be able to call the functions to execute whatever that ability is. To prevent hard coding of the abilities within the character script you can use a JSON text file that has the configuration of each character then you can load this when a Character is Instantiation and instantiate each ability using reflection and store it in the ability list of the character.

Hope that helps and makes sense.
