Download

How to design Spells Code / BP Structure

Hi,

since I am new to Unreal I have a question about how to create my code / Blueprints for spells. Whenever the character casts a spell, it can have various effects. Possible outcomes:

  • Create area of effect that damages players
  • Create a projectile that damages a player on hit
  • Enchant a player with various effects

So right now I am mostly wondering how to design enchantments of other players. For example I want to create an enchantment that prevents any damage that exceeds 10% of the players max health points.

For this I want to create a base class that has a function like float CheckDamage(APawn* Target, float Damage) that can be overriden and implemented by my spells, e.g. in this scenario to only return 10% of the max health of the target.

Now my question is, what should my spell class derive from? Should it be an actor and should I attach it to the target? All spells have a visual animation or effect so it could make sense to implement them as actors. But the effect will last even when the visual part is complete, so keeping this functionality as an actor attached to another actor might be overkill, when I don’t need it for the animation anymore.

Would it be better to create a separate class and derive from UObject for these kinds of enchantments, that live separated from the animation?

Thanks in advance

How about actor components?

Have a quick read and see whether it would make sense for you:

https://answers.unrealengine.com/questions/899785/view.html


You could then have spell actor that creates and attaches a component to the target.

1 Like

Check out how the first person shooter projectile works.

You can then make many different projectiles. Some can set a big collision component to active upon detonation for an area of effect.

You can check out the ability system if you want,

and look over the Action RPG project.

1 Like

Thank you both! The ability system sounds like it is exactly what I need, thanks a lot!

1 Like