[2.1.9] Calling `set_blueprint_entities` with the (unmodified) result of `get_blueprint_entities` can corrupt BPs

Post your bugs and problems so we can fix them.
The_LORD_thy_GOD
Inserter
Inserter
Posts: 22
Joined: Sun Nov 10, 2024 5:23 pm
Contact:

[2.1.9] Calling `set_blueprint_entities` with the (unmodified) result of `get_blueprint_entities` can corrupt BPs

Post by The_LORD_thy_GOD »

The Issue
When "Select New Contents For This Blueprint" is used, during the corresponding `on_player_setup_blueprint` event, calling `.set_blueprint_entities()` with the (unmodified) return result from `.get_blueprint_entities()`, corrupts the blueprint. Specifically it appears to shift rail entities down and to the right by one tile from where they should be, causing strange overlaps and impossible entity stacks in the blueprint.

I would expect this operation to be the identity operation, leaving an unmodified blueprint.

This does not appear to occur when creating a fresh blueprint; only when replacing contents.
Reproduction Steps
1) Load this BP into inventory:

2) Stamp it down in the world somewhere.

3) Create and enable a mod with the attached `control.lua` script.
control.lua
(724 Bytes) Downloaded 25 times
4) Open the blueprint from (1), choose Select New Contents, and select everything that was stamped down in (2).

5) Observe that the blueprint appears to have been corrupted. (the rail signal on the bottom is now impossibly stacked with its rail and the rails have shifted to the right of their original positions)
Last edited by The_LORD_thy_GOD on Wed Jul 08, 2026 7:31 am, edited 1 time in total.
The_LORD_thy_GOD
Inserter
Inserter
Posts: 22
Joined: Sun Nov 10, 2024 5:23 pm
Contact:

Re: [2.0.77] Calling `set_blueprint_entities` with the (unmodified) result of `get_blueprint_entities` can corrupt BPs

Post by The_LORD_thy_GOD »

I believe I may have further isolated the cause from further testing:

- If the "Snap to Grid" options for the BP being replaced are disabled altogether, the issue does not occur.

- When "Snap to Grid" is enabled, the various grid-snapping values contribute to the issue, with different values either causing or not causing it. I believe the cause may be an "odd+odd=even" offset from the global grid.

This Bp (Snap to 10x10, no adjustments) DOES NOT exhibit the issue:


This BP (Snap to 10x10, odd+odd=even tile offset from absolute + local grid shifts) DOES exhibit the issue:


So to sum up findings, blueprints with rails (or probably other build-grid-2 things) that have "odd+odd=even" positioning relative to the global grid are, specifically, getting corrupted by this operation. (This also probably explains why creating a new BP doesn't exhibit the issue, because there's no snapping by default)
The_LORD_thy_GOD
Inserter
Inserter
Posts: 22
Joined: Sun Nov 10, 2024 5:23 pm
Contact:

Re: [2.0.77] Calling `set_blueprint_entities` with the (unmodified) result of `get_blueprint_entities` can corrupt BPs

Post by The_LORD_thy_GOD »

I have additional information that hopefully will help find a solution.

- First, this bug is still present in Factorio 2.1.9.

- Second, I have come up with a very minimal reproduction. All steps require the `control.lua` I posted earlier to be enabled in a mod, which is basically just calling `set_blueprint_entities` with the result of `get_blueprint_entities` everytime a blueprint is extracted.

1) Place down a straight rail facing north. Create a blueprint of it with the following snap settings:
07-08-2026, 00-12-16.png
07-08-2026, 00-12-16.png (221.29 KiB) Viewed 130 times
2) Open the blueprint and choose Select New Contents For This Blueprint, selecting the same straight rail. The blueprint becomes this:
07-08-2026, 00-15-27.png
07-08-2026, 00-15-27.png (220.63 KiB) Viewed 130 times
The rail has shifted down-right in blueprint space.

3) Save the updated blueprint and pick it up in the cursor. It looks like this:
07-08-2026, 00-17-03.png
07-08-2026, 00-17-03.png (15.24 KiB) Viewed 130 times
The rail is shifted down-right yet again when in cursor, presumably to get it back onto the correct rail grid.

This is now a steady/state of the process and repeating Select New Contents will cycle 2->3->2...

This appears to be somehow a consequence of `set_blueprint_entities` on any blueprint with odd grid position combined with odd absolute offset containing entities with `build_grid_size=2`
Post Reply

Return to “Bug Reports”