Add event for when a unit_group is destroyed

Coming soon!
Post Reply
asher_sky
Inserter
Inserter
Posts: 46
Joined: Sun Oct 18, 2020 7:13 pm
Contact:

Add event for when a unit_group is destroyed

Post by asher_sky »

TL;DR
The ability to know when a unit group is destroyed, via something like defines.events.on_unit_group_destroyed or register_on_unit_group_destroyed()
Why ?
When a cutscene target dies or is destroyed, the camera abruptly teleports to 0,0. In my trainsaver mod, to prevent this I register the cutscene target entities with register_on_entity_destroyed() and restart the cutscene as appropriate when triggered. However there does not appear to be any event for when a unit_group is destroyed. I can potentially write some on_tick check to ensure the target is still valid, but that adds additional complications, and still leaves the potential for the camera to go to 0,0, even for just 1 tick. It would be much more simple to just have an event to listen to.

heyqule
Long Handed Inserter
Long Handed Inserter
Posts: 56
Joined: Sun Mar 05, 2017 1:35 am
Contact:

Re: Add event for when a unit_group is destroyed

Post by heyqule »

This would be useful for enemy AI mods.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2326
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Add event for when a unit_group is destroyed

Post by boskid »

TLDR part is implemented for 2.0 as there was "register_on_object_destroyed" implemented that supports unit groups. It may be slightly tricky because it has the same limitations as register_on_entity_destroyed - depending on when unit group is destroyed, the event may be raised in current or next tick and there are some implementation details about unit groups as they transition through a "dead" state before being destroyed causing them to be no longer valid but not yet destroyed. Lets consider this implemented for 2.0 but once it will be out and you see some issues just open new topic describing what is wrong.

Post Reply

Return to “Implemented for 2.0”