Unit groups are nil on units during the on_entity_died event.
Long version:
If you load the attached save with the attached mod, you can run the command below in the console to generate a unit group with 10 small biters.
The unit group will spawn close enough to turrets to agro the unit group.
The command when run will print the unit number and the group number of each biter.
The mod contains a hook for the on_entity_died event, where the code prints out the unit number and the group the dying biter is associated with.
None of the biters passing through the on_entity_died contain a unit_group
Code: Select all
local surface = game.surfaces[1]
local group = surface.create_unit_group({position={0,0}})
for i = 1, 10 do
local e = surface.create_entity({
position = {0,0},
name = "small-biter"
})
group.add_member(e)
print("unit", e.unit_number, "group", e.unit_group.group_number)
end