- Home /
Ability System with ScriptableObject
I'm trying to make a ScriptableObject Ability System for my grid based game.
public class Skill : ScriptableObject
{
public SkillDamageProperty[] damageProperties;
public void ApplySkill(Vector2Int position)
{
MapPositions positions = GameObject.Find("Map").GetComponent<MapPositions>();
// Damage
for (int i = 0; i < damageProperties.Length; i++)
{
Vector2Int target = position + damageProperties[i].position;
GameObject obj = positions.GetPosition(target);
if (obj == null) continue;
Stats entity = obj.GetComponent<Stats>();
if (entity == null) continue;
entity.Health -= damageProperties[i].damage;
}
}
As this class is a Scriptable Object I can create multiple skills and select which positions take damage in the inspector.
Beside damage, I want the skills to apply other effects to the enemies (like stunning, pushing, setting them on fire, etc). This effects would also be assigned to each skill in the inspector.
Now here's my problem: different effects may require diferent arguments (burning requires int duration
, pushing requires Vector2Int direction
, and so on). How could I assign diferent types of arguments in the ispector?
I thought about 2 ways of doing this, but both ways have problems:
I could create a class like I did for the damageProperties and then use subclasses for each type of effect. The problem here is that subclass variables don't show up in the inspector.
My other Idea was to make a UnityEvent and assign one function to each effect in the inspector. Here I have 2 problems: I can only pass one argument in the inspector (and I may need more arguments for some effects) and if I pass the arguments in the inspector I cannot pass the entity that's going to get it when I call event.Invoke();
Answer by $$anonymous$$ · Nov 23, 2020 at 01:26 PM
Check this videos out
You can make a script for each ability deriving from a ability script
$$anonymous$$y game is grid based. The only thing that changes between abilities is the positions on the grid that that take damage.
Right now I have 2 types of Effects that I want some abilities to use: Stun and Push. I could create a subclass for using the Stun effect, other for using Push and another for using both.
The problem with that method is that I would have to double the number of subclasses everytime I wanted to add a new type of Effect.
Your answer

Follow this Question
Related Questions
Unity 2D: How to keep player within boundary and more in the picture below 2 Answers
Confused about custom GameObjects,Custom GameObject confusion 0 Answers
Auto-refresh assets after changing scriptable object 0 Answers
Animate ScriptableObject field? Why not? 0 Answers
Can't assign rigidbody/transform variables to an extension class asset 0 Answers