Download

How does DamageType work?

So what I am trying to do is to use the DamageType method of selecting a class to define data & functionality for other things like casting a spell or activating a character item.

But I don’t really understand what is happening with the DamageType.
Take the node “apply damage”. I select a Damage Type Class and when that function is called, some magic happens and I receive the Damage Type reference through some event damage node.
So what is really happening? It would seem to me that it simply constructs the UObject of the Damage Type Class we chose.

But the description of DamageType says
"A DamageType is intended to define and describe a particular form of damage and to provide an avenue for customizing responses to damage from various sources.

For example, a game could make a DamageType_Fire set it up to ignite the damaged actor.

Damage Types are never instanced and should be treated as immutable data holders with static code functionality. They should never be stateful."

So what is going on here?

Use them like an enum.

When handling damage use a cast to determine which type

Say I make a setup where I can select a specific DamageType, for example in a data table. I get how I can get class default data, but how do I access functions inside that DamageType Class without instancing? (I assume that “construct Object from class” is the same as instancing?)

What happens between the apply damage -> ? -> Event Any Damage?

I don’t really want to use them as an enum, I’ve been down that route. Trying to keep logic away from the character, trying to keep helper actors low and trying to not create a bunch of UObjects all over the place.

One approach is to have the damage receiver determine how to respond to the damage.

Eg skeleton responds to fire damage differently than the tree ent.

The actual damagetype is really used like an enum value.

This makes sense, because the damage knows nothing of sender nor receiver and really cant be authoratative for response

I found out that if you are making singleplayer then default damage system is overkill and much less flexible than own message system that can be done in blueprints.

What I have done is, when a damage event happens, message the damagetype with the actor reference. If it has a message function, then it messages back to the actor with whatever messages it may have. A fire damagetype would message “set on fire” or whatever.

At first I tried having all the logic inside the ‘usable item’ but I realized that’s not a good idea. So the actor has to have the functions, waiting to be messaged.
Seems to be working well, I may move the functions to an actor component which I only recently started utilizing so they can be reused.