Hi, thank you for reading!
I’m making a tower defense game. I have a tower that fires a homing projectile to its target, hits, applies a brief stun, and does damage to enemys within a certain range. Everything works correctly when the projectile doesn’t do enough damage to kill the target. However, if the projectile kills the target, then the area of effect damage applies in a strange way…usually only targeting every other enemy in range when it should be targeting all of them.
For example, the AOE damages enemy1, enemy3, enemy5, enemy7, when it should be damaging EVERY enemy in range (enemy1, enemy2, enemy3, enemy4, enemy5, enemy6, enemy7, etc.).
The picture listed shows how I cast to the enemy actors. I am baffled by what is occurring, any ideas?
Have you tried placing a debug print statement if your IsValid check fails? I imagine TakeLightDamage may be queuing the Actor up for destroy and so the IsValid check would fail.
I just did as you suggested…didn’t find anything useful from looking at the debug info for the blueprint, but maybe I was looking in the wrong spot?
Its actually okay for the IsValid check to fail…the array it allows addition to is only used to later unstun hit enemies. So if an enemy survives the AOE, they will be added to the array and regain their movement speed later after passing another IsValid check to see if they are still alive.
If the IsValid check fails, is that somehow breaking the forloop? I would think it would fail the IsValid check, and loop back to the next overlapping actor…but it seems like its skipping actors
You are also checking the Healthbar for IsValid and not the Actor itself. I wonder if it’s silently failing that and causing some internal script assert. I’ve had Blueprints that act too well behaved when things go wrong. You may want to add a check to the Target after the damage is applied and not just Healthbar.
Weird, that seems like a bug.
Now I’m thinking it may be how the getOverlappingActors function stores items in an array–going to look at that
Yea thats what it was…I’m not exactly sure how the getOverlappingActors function works…maybe it fires every frame by itself, but having it plugged directly into the loop broke it. I had to set the getOverlappingActors function to a new array, then plug that array into the loop and now everything works. This seems redundant, but it works.
Thanks , you helped me get to the answer!