- Home /
Skill system
So the game I'm developing has skills.
All of them share some info: name, description, etc...
But each one of them resolves in a different way: deal damage based on a formula, heal, apply debuffs, spawn monsters, exit combat, etc...
.
After some research I've come with two implementations.
1. One scriptableobject for each skill which contains the skill data. The scriptableobject has a resolve method which uses a static resolver that works based on skill id.
2. One gameobject/prefab for each skill with a custom script for each skill that contains the resolve logic and a variable for the skill data (scriptableobject)
.
Which method is the best?
Is there a performance downside of having a prefrab+script+sciptableobject for each skill?
Should I consider any other method?
In case of using method 1, how do I handle the IDs? Right now I'm hardcoding them and feels bad a solution.
.
Any advice is welcome.
.
Here is the code for both methods:
Method 1: scriptableobject + resolver
[CreateAssetMenu]
public class Skill : ScriptableObject
{
public int id;
public string name;
public string description;
...
public void resolve(Unit self, Unit target)
{
SkillResolver.resolve(this, self, target);
}
}
public static class SkillResolver
{
public static void resolve(Skill skill, Unit self, Unit target)
{
switch (skill.id)
{
case 1:
target.takeDamage(self.AttackPhysic);
break;
}
}
}
.
Method 2: gameobject/prefab + script + scriptableobject
public abstract class Skill: MonoBehaviour
{
public SkillData skillData;
public abstract void resolve(Unit self, Unit target);
}
public class BasicAttack : Skill
{
public override void resolve(Unit self, Unit target)
{
target.takeDamage(self.AttackPhysic);
}
}
[CreateAssetMenu]
public class SkillData : ScriptableObject
{
public string name;
public string description;
...
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612233720im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to prevent an inherited variable from showing up on a scriptable object? 1 Answer
Item data structure - Scriptable Object Inheritance problems 1 Answer
Calling a derived class (Serialized in a Scriptable Object) returns the super class. 1 Answer
Can you allow inhereted ScripableObjects to be linked in the editor without dragging and dropping. 0 Answers