Need a way to keep track of ghosts that are build using robots

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
SWeini
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Mon Apr 04, 2022 6:43 am
Contact:

Need a way to keep track of ghosts that are build using robots

Post by SWeini »

With my mod a player can select entities (including ghosts), and then configure stuff. Currently I store the unit_number of the selected entities, however when the ghosts are build by construction bots I lose track of them (the entity has a new unit_number). So when working with a ghost build that is slowly built by bots, the player has to reselect over and over again to have all the entities. (https://mods.factorio.com/mod/sw-rates-calc-extreme)

What I tried so far:

Assign a tag with the ghosts's unit_number to a ghost that gets built. Then when bot (or player) builds the entity I get access to the ghost's unit_number in on_robot_built_entity.tags and can change the set of selected entities. The issue is that anyone copy-pasting something on top of a ghost overwrites/removes the tag. I don't get a lot of events when copy-pasting, just an on_pre_build event.

What I would like to see:

Add a field to on_robot_built_entity/on_built_entity/on_space_platform_built_entity events with the ghost's unit_number (I guess the ghost itself as LuaEntity doesn't exist anymore).

or

Add an event for when entities change due to a blueprint being pasted. This could be much larger than just changes in tags - also control behavior, modules, ...
Rseding91
Factorio Staff
Factorio Staff
Posts: 16790
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Need a way to keep track of ghosts that are build using robots

Post by Rseding91 »

SWeini wrote: Sat May 09, 2026 11:44 am ... however when the ghosts are build by construction bots I lose track of them (the entity has a new unit_number).
They do not have new unit numbers. The same unit number of the entity while in ghost form is used when built by robots. You simply aren't reading the actual entity unit number: https://lua-api.factorio.com/stable/cla ... nit_number
If you want to get ahold of me I'm almost always on Discord.
User avatar
Thremtopod
Inserter
Inserter
Posts: 31
Joined: Wed Nov 06, 2024 8:52 pm
Contact:

Re: Need a way to keep track of ghosts that are build using robots

Post by Thremtopod »

Add an event for when entities change due to a blueprint being pasted. This could be much larger than just changes in tags - also control behavior, modules, ...
You can use Blueprint manipulation library to achieve this. It has a function that maps blueprint entities to the entities they overlap with; you can use it during a handler for defines.events.on_pre_build.
Last edited by Thremtopod on Sat May 09, 2026 5:02 pm, edited 1 time in total.
SWeini
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Mon Apr 04, 2022 6:43 am
Contact:

Re: Need a way to keep track of ghosts that are build using robots

Post by SWeini »

Rseding91 wrote: Sat May 09, 2026 12:21 pm
SWeini wrote: Sat May 09, 2026 11:44 am ... however when the ghosts are build by construction bots I lose track of them (the entity has a new unit_number).
They do not have new unit numbers. The same unit number of the entity while in ghost form is used when built by robots. You simply aren't reading the actual entity unit number: https://lua-api.factorio.com/stable/cla ... nit_number
I might not understand something properly. If I build a ghost it has ghost_unit_number=nil, that doesn't help me. If the ghost is built, then the new entity has a different unit_number.
SWeini
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Mon Apr 04, 2022 6:43 am
Contact:

Re: Need a way to keep track of ghosts that are build using robots

Post by SWeini »

Thremtopod wrote: Sat May 09, 2026 1:22 pm
Add an event for when entities change due to a blueprint being pasted. This could be much larger than just changes in tags - also control behavior, modules, ...
You can use Blueprint manipulation library to achieve this. It has a function that maps blueprint entities to the entities they overlap with; you can use it during a handler for defines.events.on_ore_build.
That might me one way to handle this - on_pre_build is the one event I get when pasting blueprints. However, the timing of this is not optimal - the entity tags are updated after the event, so I'd have to delay updating the tags until after the blueprint was applied. Might be possible, but not very convenient, especially considering I need a non-trivial library as dependency just to do this. If everything else fails I might resort to it.
SWeini
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Mon Apr 04, 2022 6:43 am
Contact:

Re: Need a way to keep track of ghosts that are build using robots

Post by SWeini »

Status update: I got it working, see https://mods.factorio.com/mod/sw-entity-tracker
The tracking in action can be found here: https://mods.factorio.com/mod/sw-rates- ... /changelog

However, I will gladly simplify the functionality if the API is changed according to what I proposed.
Post Reply

Return to “Modding interface requests”