Page 1 of 1

[2.0.66] Belt dragging cancels rotations

Posted: Sat Sep 20, 2025 4:00 pm
by Loup&Snoop
This feels like a niche edge case, but the spirit of Bilka compels me to report it.
The Bug
  • In an on_built_entity event callback: if entity.direction == defines.direction.west then entity.rotate{by_player=player_index} end
  • Boot up a new sandbox save. Cheats on.
  • Put a stack of belts AND the relevant underground into your inventory.
  • Place 2 vertical belts side by side.
  • With the cursor, start dragging a belt from right to left, starting to the right of the belt you placed. The script automatically rotates the belt from left (west) to up (north).
  • Continue dragging all the way left across to place an underground belt.
  • The script you place got called and successfully rotated the underground belt from west (12) to east (4)... but the underground belt is currently oriented WEST (not east!).
Expected Outcome
That belt should stay facing east.
Included Test Mod
I am including a simple test mod with the following code, to make your life easier. Please run it with ONLY base and this mod.
rotation-bug-test_420.69.1.zip
Bug test mod
(962 Bytes) Downloaded 11 times
09-20-2025, 11-40-06.png
09-20-2025, 11-40-06.png (38.46 KiB) Viewed 354 times

With this test mod, I did the above procedure, and got this result. Notice that the game log says it successfully rotated the 3rd belt AND the underground belt. The 3rd belt was properly rotated, but the underground was not.
2025-09-20 11-35-20-TheBug.mp4
The bug
(4.03 MiB) Downloaded 12 times

Control experiments, with everything working as intended.
2025-09-20 11-36-21.mp4
Control experiment
(4.06 MiB) Downloaded 11 times

I also tested entity.health = 10 instead of entity.rotate, and the health reduction DOES persist properly. This indicates that the issue seems unique to rotation. Given how my main mod works, I'm fairly certain that this bug did not happen in previous versions of factorio. I could be wrong, but it likely started in the back-and-forth changing of belt dragging in the recent stable version(s) of factorio.

Re: [2.0.66] Belt dragging cancels rotations

Posted: Fri Sep 26, 2025 3:16 pm
by boskid
Thanks for the report. Given that you are manipulating entities while drag building happens, i am considering this to be an interference between smart belt building logic and your mod logic. If we would be required to behave nicely in presence of mods that do not behave nicely for smart belt building logic, then complexity of smart belt building code would grow exponentially, and we do not even know what mods may do inside of the build events. If you want to rotate the entities, please do so in a different event. I will classify this as a Not a bug.

Re: [2.0.66] Belt dragging cancels rotations

Posted: Fri Sep 26, 2025 5:38 pm
by Loup&Snoop
Thank you for the response.
boskid wrote: Fri Sep 26, 2025 3:16 pm If you want to rotate the entities, please do so in a different event.
What event would you suggest? I agree that it is best if our mod avoids modifying entities until the engine is done modifying them.

I do not see other promising events in the Event Tracer mod (https://mods.factorio.com/mod/0-event-trace). My current workaround is to queue up a second function call on the same entity for next frame, but a proper event callback would be optimal.

Re: [2.0.66] Belt dragging cancels rotations

Posted: Fri Sep 26, 2025 6:11 pm
by Rseding91
That’s what you would do: queue them for modification next tick (via on_tick)