Identify entities whose on_built_entity hasn't triggered yet

Things that we aren't going to implement
sparr
Smart Inserter
Smart Inserter
Posts: 1519
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Identify entities whose on_built_entity hasn't triggered yet

Post by sparr »

When a blueprint creates multiple entities, it seems like they are all created in the world, then on_built_entity is triggered for each of them. This means that while one on_built_entity is running, it can see in the world other entities whose on_built_entity hasn't run yet.

I'd like a way to check whether an entity has a pending on_built_entity (or other event?). Something like LuaEntity.has_pending_events as an array of defines.events values?
protocol_1903
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Sep 09, 2022 4:33 pm
Contact:

Re: Identify entities whose on_built_entity hasn't triggered yet

Post by protocol_1903 »

+1, i had a number of issues along similar lines. Would also like to see this applied to events like on_marked_for_deconstruction when the player selects multiple entities.
If you need to reach me, message me on discord.

I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
sparr
Smart Inserter
Smart Inserter
Posts: 1519
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Identify entities whose on_built_entity hasn't triggered yet

Post by sparr »

Similar results could be had from another angle if we had a way to query the events in the queue. Something like game.get_queued_events returning an array of pairs of event type and event data, for events queued to be handled by the current mod that haven't been triggered yet. Then I could loop through that array to find out if there's a queued event for the entity in question.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15790
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Identify entities whose on_built_entity hasn't triggered yet

Post by Rseding91 »

Unfortunately this simply isn't possible and I don't see it ever being possible. There are never events in the queue because there is no event queue - all* events happen instantly as the C++ logic sends them. The way blueprints work is the game first puts all of the entities in the world, sets them all up, then runs over them 1 at a time and sends the Lua event for them being created.

* Some events are sent at the end of the tick - but are not themselves "delayed" - they simply record that they need to be sent and the processing of them happens at the end of the tick (player inventory change notifications and object-destroyed notifications).
If you want to get ahold of me I'm almost always on Discord.
sparr
Smart Inserter
Smart Inserter
Posts: 1519
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Identify entities whose on_built_entity hasn't triggered yet

Post by sparr »

Rseding91 wrote: Tue Jun 10, 2025 2:23 pmThere are never events in the queue because there is no event queue [...] then runs over them 1 at a time
I'm having trouble imagining how this can be true. Obviously I haven't seen the source code, but the only implementations of this I can think of involve access to a list of the entities that were just created. Maybe it's being iterated and the whole list is still available, or maybe it's a queue or stack and only the unprocessed part of the list is still available, but at each cycle of that "1 at a time" it must be finding the next one somewhere/somehow.
sparr
Smart Inserter
Smart Inserter
Posts: 1519
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Identify entities whose on_built_entity hasn't triggered yet

Post by sparr »

PS: This is an XY post. The underlying problem/goal here is finding a way to prevent https://mods.factorio.com/mod/automatic ... connectors from building a pipe ghost between two new underground pipe ghosts in the middle of a blueprint placement. The broader inquiry into how to solve that sort of problem with that mod is at viewtopic.php?t=129325
Rseding91
Factorio Staff
Factorio Staff
Posts: 15790
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Identify entities whose on_built_entity hasn't triggered yet

Post by Rseding91 »

sparr wrote: Tue Jun 10, 2025 2:54 pm I'm having trouble imagining how this can be true. Obviously I haven't seen the source code, but the only implementations of this I can think of involve access to a list of the entities that were just created. Maybe it's being iterated and the whole list is still available, or maybe it's a queue or stack and only the unprocessed part of the list is still available, but at each cycle of that "1 at a time" it must be finding the next one somewhere/somehow.
There is an array of entities somewhere in the process that it's iterating over but there's no central-ness to it, no uniform way for anything to know that such a list is being iterated and no way to uniformly or even cleanly expose such a list to Lua. Those kinds of lists exit anywhere the game is doing some operation on several things at once since it has to keep track of what it's doing.

That's to say: asking for "those lists" to be available for Lua to read in some way just isn't viable. The entire game was never setup for such a thing. Shoe-horning it in would be a huge mess, and trying to restructure everything to make it possible is outside the scope of anything we want to support modding wise.
If you want to get ahold of me I'm almost always on Discord.
sparr
Smart Inserter
Smart Inserter
Posts: 1519
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Identify entities whose on_built_entity hasn't triggered yet

Post by sparr »

OK, how about a more limited scope, *just* for entities being created by a blueprint?
Rseding91
Factorio Staff
Factorio Staff
Posts: 15790
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Identify entities whose on_built_entity hasn't triggered yet

Post by Rseding91 »

Given we've gotten 10 years into Factorio without it, and it wouldn't encompass all of the places where such a thing happens, I have no interest in trying to shoe-horn such a thing into the game.

There are limits to the modding API and this happens to be one of them. It may end up that the mod you're attempting to make simply can't be done in Factorio.
If you want to get ahold of me I'm almost always on Discord.
protocol_1903
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Sep 09, 2022 4:33 pm
Contact:

Re: Identify entities whose on_built_entity hasn't triggered yet

Post by protocol_1903 »

perhaps on_player_built_blueprint could run before on_built?
If you need to reach me, message me on discord.

I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
Post Reply

Return to “Won't implement”