Allow mod to track entities across undo

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
GlassBricks
Inserter
Inserter
Posts: 25
Joined: Fri Jun 11, 2021 5:20 pm
Contact:

Allow mod to track entities across undo

Post by GlassBricks »

It is often desirable to attach some data to an entity, this can be done for instance, with a table by unit_number in global.
However an entity is deleted, then the deletion is un-done. there is no way to remember or recover this data. The unit number changes, there's no other identifying info.
The workaround I've seen used is to have a "dummy-combinator" holding the settings with the actual functional entities being hidden. However, this doesn't work with "attaching" data to vanilla/existing entities.

Some ways that this could be done:
- Provide another "unit_number" thing, such as, "id_number", that stays the same for an entity when it is deleted/undo, died/revived, etc..
- Better, the dream would to let entities to have "custom_tags" that lives and dies with the entity, like the "tags" for blueprint ghosts, but for all entities; this would live through undo, die/revive.
- An extension of the previous idea, let the "custom_tags" be copy/paste-able through blueprinting too. This would also make it much, much easier for mods to store custom entity settings in blueprints, and allow multiple mods to do so simultaneously.

The last option seems like the most logical option. I don't know why it hasn't been done like this previously, but I'll trust the devs have their reasons for it.

GlassBricks
Inserter
Inserter
Posts: 25
Joined: Fri Jun 11, 2021 5:20 pm
Contact:

Re: Allow mod to track entities across undo

Post by GlassBricks »

Another potential way to do this is to add a "old unit_number" field to events when undo is done. This means more work for the mod, but at least the mod can detect the undo and what entity it used to correspond to.

BlackOverlord
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Aug 20, 2021 5:00 pm
Contact:

Re: Allow mod to track entities across undo

Post by BlackOverlord »

+1

I think a pretty easy solution could be to set ghost_unit_number to the unit_number of the removed entity which is being undone by the ghost. The same way it works with ghosts placed after killing an entity.

Post Reply

Return to “Modding interface requests”