REPENTOGON icon indicating copy to clipboard operation
REPENTOGON copied to clipboard

Unexpected behaviour when using entity:Kill() while iterating through FindInCapsule/FindInRadius

Open Spearkiller opened this issue 1 year ago • 2 comments

I'm making a familiar (Which, in this situation, is technically a bomb due to complications regarding TryThrow not working on familiars, but that's besides the point but feel it worth mentioning just in case that plays a part in the issue) that when thrown, destroys any projectiles that it collides with. I have been doing this with

for k, v in pairs(Isaac.FindInCapsule(bomb:GetCollisionCapsule(), EntityPartition.BULLET)) do
        v:Kill()
end

A note that this is done in a MC_PRE_BOMB_UPDATE callback. POST_BOMB_COLLISION does not fire in this circumstance.

When testing, I found that, inexplicably, enemies would randomly die when hit by my familiar/bomb. After some further experimentation, I found that removing the v:Kill() call stopped this from happening.

Some other things I have tested/noticed:

  • Sometimes, entities outside of the collision capsule would be killed instead.
  • Doing print(v.Type) always printed "9" into the console (EntityType.ENTITY_PROJECTILE)
  • Changing it to if v:ToProjectile() then v:Kill() end had no effect and npcs would continue to randomly die as before.
  • Using FindInRadius also demonstrated strange behaviour.
  • Changing it to Remove() works as expected.
  • Creating a table, copying all the entities to be killed into that table, and then doing a second iteration through that, also checking if v:ToProjectile() then did not stop non-projectiles being killed.

Initially I had thought this was just an issue with FindInCapsule, but further testing has left me stumped.

Spearkiller avatar Dec 24 '24 12:12 Spearkiller

Your title mentions FindInRadius in addition to FindInCapsule, but I can't seem to find any references to it in the description of the issue ? Did you do some tests with FindInRadius, or is it a typo in the title of the issue ? (I'm asking because I'm more familar with FindInRadius... Extremely questionable implementation, so what you describe would not surprise me that much if it applied to FindInRadius)

Sylmir avatar Dec 24 '24 13:12 Sylmir

oop, I mustve forgotten to mention it, but yes, I tested using FindInRadius as well.

Spearkiller avatar Dec 24 '24 13:12 Spearkiller