Non-hideous TakeDamage call chain

I’ve had a custom damage/damage type set-up in my project for a while and was looking at swapping over to the inbuilt damage system. My main question is if you do have multiple damage types, for arguments sake ‘health damage, fire damage, ice damage’ when you’re implementing the ‘Event Any Damage’ is there a way to avoid casting to every single damage type you have? ie.

This set-up will get really messy if expanded to have like 20 odd damage types. And there’s no real way to ‘switch on damage type’ since it’s being fed in as the damage type class, not an enum.

Am I just going about this entirely wrong? Or is there a neat solution here?

Just as some added information, this is the set-up I’ve made currently. It’s neat enough with the re-routes, but I can’t help feel I’m not using the damage types correctly. Is this the intended workflow for them?

You can call the damage with an interface, the only difference is that you’d have to adjust some server/client preferences manually if you have multiplayer.

Hey, kinda necroing, but did you ever find a good way to do this? I’m trying to figure out how to exec different logic OnTakeDamage based on DamageType, and while doing what you’ve done may work, what I’m working on is a multiplayer game and I want it as optimized as possible meaning that going through a long casting chain might not be the fastest. I’m gonna look into these interfaces, maybe that’s what I need. Please give a hoot if you found a solution that works for you Hennez! :slight_smile:

No unfortunately I never got this working. I had an interface set-up working initially then figured if there was an inbuilt damage type system it’d probably be best to use that. But I did end up reverting to my previous interface solution.

Okay I found a solution to this, don’t know if it’s the most elegant solution, but at least you only have to cast once!

First off, create a new DamageType blueprint, this will be the parent. Make as many children as you need damagetypes based on this. Now, make a struct that holds all the info that you need from your damagetypes and set that as a variable in your parent DamageTypeBP. I included an enum in this struct, which gives me the oppurtunity to “Switch on DamageTypes” when someone takes damage, so I can execute different code using the same variables if I have to.

So in your OnTakeDamage event, just grab the DamageType object, cast to your parent DamageTypeBP and get+break the struct and you will have all the variables you need to perform whatever your damagedesires need!