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:
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 :)
Any help would be greatly appreciated!
asked Mar 13 '18 at 06:30 PM in Blueprint Scripting
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
answered Mar 13 '18 at 07:02 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here