When a segmented-unit is killed by destroying its head or another segment it correctly fires defines.events.on_entity_died for the head.
When a segmented-unit is destroyed with editor by right clicking on its head, it correctly fires defines.events.script_raised_destroy. However this event does not fire for the head when destroying the unit by right clicking on one of its segments. I'm assuming this also applies to other script based removal methods.
This is inconsistent and inconvenient because there isn't a way to get a reference to the head segment when a body segment gets removed. (Required when using the unit_number to keep track of these enemies).
I'm happy to test any situation to narrow down the discrepancy if desired!
[2.0.32] Segmented units destroyed with editor do not always fire event for the head
Re: [2.0.32] Segmented units destroyed with editor do not always fire event for the head
Thanks for the report however this is not a bug. script_raised_destroy is called when the body piece is removed, and as part of removing the body piece - through any means - the unit is destroyed. You will get the same behavior if you game.player.selected.destroy() a piece of the segmented unit.
If you want to know when the head goes away in all cases that's what https://lua-api.factorio.com/latest/cla ... _destroyed is for.
If you want to know when the head goes away in all cases that's what https://lua-api.factorio.com/latest/cla ... _destroyed is for.
If you want to get ahold of me I'm almost always on Discord.