Character can throw different objects, which have different damage values when hitting enemies, how do I go about this?

In my project, my character can launch 4 different projectiles. How do I make it so that when an enemy is hit, it detects which projectile it was hit by, and then takes the appropriate amount of damage?

Every tutorial I have seen for projectile and enemy damage only allows for detection of one specific projectile, which is casted to on an On Component Begin Overlap event. This obviously wouldn’t work because I have multiple things with multiple values.

What is the solution?

Every tutorial I have seen for
projectile and enemy damage only
allows for detection of one specific
projectile, which is casted to on an
On Component Begin Overlap event. This
obviously wouldn’t work because I have
multiple things with multiple values.

Precisely. Or you may not even have projectiles in your game. Or take fall damage or need to apply damage due to physical interaction, apply constant damage when nothing is happening until a specific condition is met… or do a bazillion other things that do not utilise projectile components or regular overlap / hit mechanics.


For something truly advanced, you may wish to write your own custom system. But the abovementioned damage system is generally enough in most cases.

UE4 comes with a built-in damage system - a bunch of events and event dispatchers facilitating the features you’re after:

317725-screenshot-2020-10-08-082711.jpg

This can be further augmented by the Damage Type objects. There should be some tutorials on YT regarding this:

I’d suggest within your “Enemy” BP you just want to apply some checks to see what component it was hit by and then run the damage taken by the object.

It may not be the best way to do it, but something like this:

Hm, this would definitely work, but I think I would want to go with an alternative method that is more efficient. The goal of the project I’m working on is to learn and in addition to that, the project will, in the end have MUCH more than just the four projectiles.

Ok, very interesting. I wasn’t familiar with the built in damage system. So would I want to break hit result on overlap and call Apply Damage to the hit actor?

I posted a comment earlier but it isn’t here, not sure what happened to it. Sort of new to these forums. Anyway… this definitely looks like what I’m looking for, I didn’t know UNreal had its own damage system worked in like this. The only thing now that I can’t seem to figure out is is the actual act of the two actors touching. My game is 2D and this is what I have, but of course, it isn’t working.

If I do a cast to a specific enemy, hitting that enemy with the projectile works fine when using apply damage. I just need to be able to detect what is being hit with the break result. I’ve been working at this for a bit now and my brain is fried from it, any ideas?

So would I want to break hit result on
overlap

That’d depend on how things are moved and whether Sweep is used for movement.

Essentially, if the actor does not implement this…

317881-screenshot-2020-10-09-114958.jpg

…nothing happens. And there’s no need to cast in most cases unless you’re after something more in-depth and start using Damage Type.

I’m not too familiar with 2d, I know how sweep works, though. Perhaps it’s enough to use the OtherActor pin on the component overlap node.

I tried that now and it seems to be working. I thought I tried it earlier though and couldn’t get it to work… Either way, thank you very much your help. ITts much appreciated!

I wouldn’t set it up like this either long term, I’d have a struct and a data table most likely, then you could run 1 loop on collision of an object, pass along an ID or something and then just have the loop return the damage amount in the data table.

I am glad you seem to have found the result you were looking for though. All the best.