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?
Identify entities whose on_built_entity hasn't triggered yet
-
- Fast Inserter
- Posts: 245
- Joined: Fri Sep 09, 2022 4:33 pm
- Contact:
Re: Identify entities whose on_built_entity hasn't triggered yet
+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.
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.
Re: Identify entities whose on_built_entity hasn't triggered yet
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.
Re: Identify entities whose on_built_entity hasn't triggered yet
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).
* 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.
Re: Identify entities whose on_built_entity hasn't triggered yet
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.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
Re: Identify entities whose on_built_entity hasn't triggered yet
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
Re: Identify entities whose on_built_entity hasn't triggered yet
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.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.
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.
Re: Identify entities whose on_built_entity hasn't triggered yet
OK, how about a more limited scope, *just* for entities being created by a blueprint?
Re: Identify entities whose on_built_entity hasn't triggered yet
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.
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.
-
- Fast Inserter
- Posts: 245
- Joined: Fri Sep 09, 2022 4:33 pm
- Contact:
Re: Identify entities whose on_built_entity hasn't triggered yet
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.
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.