Need the communities input - Spell System

So I am struggling a bit with a really well oiled Spell casting system. I have one in place right now that works, but it is clumsy and error prone.

Here are the horrid details:
-I have a spell object which contains all the spells info (duration, damage, type (self, area, target based), recast time, etc…) - so far so good.

-The spell object also contains a reference to three prefabs, a “casting” effect, a “flight” effect, and a “hit” effect.

-when the user casts a spell, the caster enters a “casting state” until the casting is done (I also instantiate the “casting” prefab (casting effect). This in turn instantiates the flight prefab (if applicable) which in turn instantiates the “hit” prefab (when a target is hit). I pass a spell info object between these prefabs which contains the target AND source info so I can try who cast the spell and who/what the target is (can be null if its an area of effect spell).

As you can imagine this “workflow” is terrible to maintain.

Has anyone else implemented a spell casting system? Its need to be flexible in that it doesn’t matter who is casting (enemy or player) or what the target is as enemies can fight one another.

Come on - too many smart people in here for me to believe no one has any thoughts!?

How to improve on this depends on the nature of the game. Rather than have the spells originate from the character’s script and then pass information in prefabs, etc, it might be better to have a centralised spell management object. This would keep track of the state of a given spell. If the game has only one character active and casting at a time, the spell manager is relatively straightforward, essentially just the information you’ve already mentioned, but concentrated in one place. If the game allows for several casters to be firing spells off at any time, then the manager will be implemented as a list of spell states. This list needs to be checked periodically to remove finished spells and update the states of all spells in progress.

Thanks for the reply. I had started working on something like that, but I couldn’t get it working as I would want. But I think I will give it another go.

My system right now works really nicely, but sucks to step through if there is an issue - in other words the code smells.