Overlap event handling in multiple actors

Hi everyone!
I have run into an error while scripting a system for my game. The problem is that 2 actors are both trying to do something when an overlap occurs. Actor 1 is supposed to be destroyed, but then Actor 2 is trying to handle the same overlap on the same tick, but can’t check the overlap anymore, as Actor 1 is pending kill.

To give some basic context:

  • I have a weapon projectile that the
    player shoots, this is Actor1. Has a
    custom collision channel called
    ‘playerProjectille’
  • I have an enemy with a hitbox, this
    is Actor2. Has a custom collision
    channel called ‘damageableObject’
  • In the player’s projectile blueprint, there’s an overlap check, if it overlaps anything with “damageableObject” channel, plays explosion, sound, and gets destroyed
  • In the enemy’s blueprint, there’s an overlap check as well, if it overlaps anything with “playerProjectile” channel, it takes damage, plays sound, loses health etc.

The problem is that when the projectile and the enemy touch, the projectile does it’s script first I guess, gets flagged to get killed, then the enemy does its check of the same overlap, but can’t access the projectile anymore as it’s flagged to be killed. If its done in the opposite order, maybe it would work, as the enemy’s script won’t destroy the projectile. BUT if the enemy is killed by the shot, it might destroy itself on the overlap, and then the projectile can’t do their part of the overlap.

Can anyone help me with how this could be worked around or fixed? I set up the collision channels for future systems where the player will shoot all different kinds of projectiles from different weapons, so instead of casting to each type of bullets and weapons, and get exponentially growing code, I wanted to handle them all under “playerProjectile” collision reactions, so every enemy will know to react to every type of projectile. I also plan to create many, many different types of enemies and breakable objects, so the same goes for the “damageableObject” collision channel. You guys know what I mean :slight_smile:

Any help would be greatly appreciated!

Instead of checking collisions on both sides, you could send some kind of message to an enemy from projectile about type of damage.
You can do that with Apply Damage node with your custom DamageType class assigned to it. In enemy blueprint you will need to assign an OnTakeAnyDamage event, and react to information, given through DamageType pin.

You can watch a video about this system: youtu.be/MLtDgukVG94