I've received a bug report yesterday because of a crash that involved accessing an invalid entity. The bug report was a case of landfill accidentally placed over an entity on water, but the same thing also happened when waterfill is placed over an entity on land.
I want to react to entities disappearing, but I haven't found a proper event yet. They are not mined, so neither on_X_pre_mined nor on_X_mined_entity trigger. The entities also don't die, so they also don't trigger on_entity_died or script_raised_destroy. Is there an easy way to check for entities that have simply disappeared?
I suppose the entities vanish because their collision mask isn't compatible with that of the placed tile. So I probably could react to on_X_built_tile. But this only triggers after a tile has been placed, and it doesn't return the entities that were at that position. I will get the position, so I could loop over the list of stored entities to get their position (except the entities don't exist anymore, so I'd get a "trying to index nil" error). Listening to on_put_item, checking if the item has a placed_as_tile result, checking the collision mask of the tile, looking for entities in that position, and comparing their collision mask with that of the tile could work -- but it's a lot of work, and landfill is usually placed en masse, so that wouldn't be UPS friendly. Does anybody have a better idea?
Looking for event (destroyed entities)
Looking for event (destroyed entities)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Looking for event (destroyed entities)
Just check that its valid before trying to do things with it...
There are many many ways entities can become invalidated without any event notification.
Re: Looking for event (destroyed entities)
Thanks! I was hoping I could avoid that. There are always those cases where you forget to check if an entity is valid -- and that will crash the game. Being notified when a relevant entity becomes invalid would allow me to prune my lists, but …
… I guess that would also put a lot of load onto the system, so there's no chance to get such an event implemented.There are many many ways entities can become invalidated without any event notification.

A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!