Spell System using Unity ScriptableObjects, Part 1

This is the first in a series of posts aimed at other Unity devs, so that depending on their skill level, they can either learn something new, or have something to mock.

Or maybe you’re just interested in the game, and are desperate for any and all information about it.

In that case, hi Mom!

Get on with it already

Ever since I saw this presentation from Unite 2016, I have been in a passionate and occasionally violent relationship with ScriptableObjects.

One of the main systems in Heal Plz is the ability/spellcasting system, so I needed a way to quickly create new spells without individually coding each one. Thus, Heal Plz’s ScriptableObject spell system was born. In just a few minutes, this:

Becomes this:

Let’s have a look at the different sections. Choosing a name and an icon is obvious, but the rest probably needs some explanation.

Skill Type

This is a dropdown with different tags that can be toggled to tell various other systems how to react to the ability.

For instance, they help the enemy AI determine the right time to use them.

As an  example, using “Emergency” and “Heal” communicates that it’s a powerful, fast casting heal spell with a long cooldown or high cost, and should only be used in gasp emergencies.

Cast Type

Cast Type is pretty simple; Standard means that after the Cast Time is elapsed, the ability activates. Creating an insta-cast or melee ability is as simple as setting the Cast Time to zero. 

Channeled spells periodically do something over the entire Cast Time. Optionally, they can do something at the beginning of the Cast Time, and at the end. This will make more sense when we go over the Spell Actions section. Maybe.

Required Target

More context for the AI to know when to do what! And for the player character, depending on their target, it also determines if their spell will cast or if they’ll get yelled at instead.

  • Enemy- Can only be used on enemies.
  • Friendly- Like Enemy, but opposite day
  • Any- Can be used on Enemies or Friendlies. The Switzerland of spells, kinda.
  • No Target- Will cast even if no target is selected.
  • Self Only- No matter what is targeted, the ability will be used on the caster.

The Section That I Am Probably Going to Rush Through

Hoo boy. Cast time is cast time. Cooldown is how long before it can be used again. Range is where the deer and the antelope play. Aggro Multiplier is how much additional threat the spell causes for purposes of enemy AI target selection.
Resist Factor is multiplies its base chance to be resisted. 2 doubles the chances to be resisted, 0 means it can’t be resisted. If heal spells could be resisted, no one would play this. Requires LoS determines whether or not spells require line of sight and Can Target Corpses determines exactly what it says mostly used for Resurrection type spells oh my gosh I’m so glad this section is over.

Resource Costs

Okay, now we’re back on something that’s actually interesting. The Resource Costs list can contain one or more resource costs, or even have a negative resource cost. This allows for interesting mechanics, like a spell that costs health to restore mana, or for abilities that are secondary resource generators and some that are secondary resource spenders.

For example, the Phoenix Cultist, one of the playable healers, has a secondary resource called Burnout that she generates when casting healing spells that can be spent to cast offensive spells. The caveat is that she takes increasingly heavy damage over time based on her level of Burnout, so keeping a balance is key.

To be continued…

Thank you for reading! Check back soon for part two, where we dig into the Action List. This is what gives the entire system so much depth and flexibility.

Questions? We’d love to answer them, comment here or swirly-a (I don’t know any of the lingo) us on Twitter.

 

Heal Plz is an MMO-inspired dungeon crawling RPG where you play as the healer of an AI-controlled group. Wishlist on Steam and follow us on Twitter for development updates!

Share This!

Share on reddit
Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp

Leave a Reply

Close Menu