`LuaRecord.is_preview` and the `on_pre_build` event.

Place to post guides, observations, things related to modding that are not mods themselves.
The_LORD_thy_GOD
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sun Nov 10, 2024 5:23 pm
Contact:

`LuaRecord.is_preview` and the `on_pre_build` event.

Post by The_LORD_thy_GOD »

(In the #mod-dev-help discord channel, Bilka asked for a forum post to be made about this issue. Link to the original discord discussion: here)

We received the following multiplayer crash report:
09-11-2025, 14-34-14.png
09-11-2025, 14-34-14.png (92.67 KiB) Viewed 185 times


Upon analysis, we found the crash is occurring in the `on_pre_build` event for a blueprint where `is_preview` is `true`.

Questions arose about the meaning of the `LuaRecord.is_preview` flag and how it could possibly be `true` for a blueprint that was actually being built. As `on_pre_build` is the "last chance" event (at least as far as I know) for mods to look at what entities a blueprint will build, it would be preferable if blueprint entities were fully readable at that point.
Bilka
Factorio Staff
Factorio Staff
Posts: 3584
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: `LuaRecord.is_preview` and the `on_pre_build` event.

Post by Bilka »

I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Bilka
Factorio Staff
Factorio Staff
Posts: 3584
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: `LuaRecord.is_preview` and the `on_pre_build` event.

Post by Bilka »

As suspected on discord, this is indeed happening because the record you get is a blueprint book that is considered a preview, but the selected blueprint is not a preview and getting placed. For 2.0.67 we've added LuaRecord::get_selected_record() which will get you the selected single blueprint record from the book even if the book is a preview. (That record may still be in preview generally, but not in this event.) Thanks for the assistance in debugging this!

Note for future readers: Preview means that it's a blueprint or book from a player's library that hasn't been loaded to the game state yet, so usually seen in multiplayer games.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Post Reply

Return to “Modding discussion”