Download

2D OnComponentBeginOverlap for Multiple Targets

Just started with UE4 (and programming in general) and followed the 2D Sidescroller tutorial from Alan Noon. Got to the end of the 2 videos he made and started expanding by myself. Right now I’m working on enemies and destroying said enemies using the shooting animation made in the tutorials. The way I set it up is that the enemies have damage systems just like the BP_Dude and I’m using BP_Shot’s OnComponentBeginOverlap to trigger the damage in the same way that damage is triggered when your character hits one of the traps. The problem is that I can only seem to use this event once per box so its only working for one enemy type. Is there a way to set up a switch so that depending on what enemy the BP_Shot collides with a different path is followed?

Here is how I currently have it set up:

5226d0cdcfa8638485c164d43b140c65a3419500.png

Using the cast failed lets me set it up for 2 enemy types, but obviously that’s not a good way to achieve what I’m looking to do.

Do all your enemy types derive from the same parent blueprint? If so you could just cast the hit result to whatever the enemy parent class is, and call the damage system function from there (each child can override the damage system function and implement it in unique ways if you like).

Possibly another alternative would be to make an interface with the DamageSystem function, and have each enemy implement that interface (again they can implement the function in unique ways if you like). Then in that overlap event just test to see if the other actor implements your interface, if it does, call the DamageSystem function on it. This way, it doesn’t matter which enemy was hit, as long as it has the DamageSystem interface attached you’ll be able to use it.

Thanks, I went ahead and set it up with the child class and it works now.