Page 1 of 1
Need a way to keep track of ghosts that are build using robots
Posted: Sat May 09, 2026 11:44 am
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, ...
Re: Need a way to keep track of ghosts that are build using robots
Posted: Sat May 09, 2026 12:21 pm
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
Re: Need a way to keep track of ghosts that are build using robots
Posted: Sat May 09, 2026 1:22 pm
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.
Re: Need a way to keep track of ghosts that are build using robots
Posted: Sat May 09, 2026 2:50 pm
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.
Re: Need a way to keep track of ghosts that are build using robots
Posted: Sat May 09, 2026 2:57 pm
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.
Re: Need a way to keep track of ghosts that are build using robots
Posted: Sat May 09, 2026 4:43 pm
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.