So I’m basically working on an ability system for my game and want to work with a “loadout” style system. So the player can edit their choice of three spells to put in their loadout for a match, and change them out for other spells.
My main issue is actually making these spells. Right now I have each spell as a ScriptableObject which contains a name, a thumbnail, some stats for cooldown and active time, and an enum containing a spell ID, a unique identifier for that spell.
I then have a script which listens for mouse or keyboard inputs and depending on which spell scriptable object is put into which slot, it corresponds to a keybinding. It then passes through that spell ID when the key is pressed into another script which reads the spellID in a switch statement and calls the function associated with that SpellID. Something like this:
public class Spellbook : MonoBehaviour
{
public SpellID eSpellID;
public void SpellCheck(SpellID spellID)
{
switch (spellID)
{
case SpellID.Icebolt:
Icebolt();
break;
case SpellID.Fireball:
Fireball();
break;
case SpellID.Smite:
Smite();
break;
}
}
}
The issue I can see with this way of doing things is that I would have one giant script with each spell and all of the prefabs and data values associated with that spell, and it doesn’t make sense to load all this data just to cast three spells out of many.
My next thought was just to have individual scripts for each spell, but that would still entail loading every script onto the player, and I could have upwards of 30 spells for example and it starts to become an issue. I could always unload the unused scripts, but they still need to be loaded first and they can be a pain to all show up in the editor.
If there was a way to have individual scriptableobjects contain different behaviors like methods that would solve my problem, but i was told that SO’s should be used for storing data and not behavior. I also am looking into things like inheritance, overrides, and interfaces, but I don’t think that solves the issue of having a bunch of scripts loaded all at once.
Appreciate any help!