[2.1.12] Erroneous error with surface.create_entity() placing CarPrototype entity ghost

Place to get help with not working mods / modding interface.
MeteorSwarm
Inserter
Inserter
Posts: 31
Joined: Thu Sep 25, 2025 10:49 pm
Contact:

[2.1.12] Erroneous error with surface.create_entity() placing CarPrototype entity ghost

Post by MeteorSwarm »

07-26-2026, 16-46-48.png
07-26-2026, 16-46-48.png (2.18 MiB) Viewed 88 times
This bug interacts with PlanetsLib's entity replacement system when creating entity replacement rules for Car Prototypes. Typically, when placing an entity on a planet with a replacement rule for that entity and planet, replace_entity() checks if the entity is a ghost by checking if "entity.name == "entity-ghost". If this is true, the entity that replaces the old entity is also an entity ghost. When placing a non-ghost vehicle, this function works perfectly, because it was designed with all LuaEntities in mind. When placing a vehicle entity ghost, replace_entity() detects that the ghost has the name "entity-ghost", and so places as an entity ghost, but when placing the new entity, Factorio throws the error "[vehicle-name] can not be part a entity ghost." At best, this error is not very descriptive of the issue, because CarPrototypes can be entity-ghosts, because this replacement would not be made an entity ghost if the entity it caught was not an entity ghost, and at worst, it's erroneously throwing an error that it should not be throwing.

One possible issue I considered is that because the newly placed CarPrototype is being placed in the location of an existing CarPrototype without immediately deleting the old entity, something completely possible with static entities, the game fails to place the new CarPrototype. To test this, I moved the old entity's position 100 units each direction before placing the new entity, but that did not change the error. The only explanation that makes sense is that this error is an artifact from before CarPrototype entity-ghosts were possible.

To reproduce:

1. Download this debug build of PlanetsLib. https://github.com/danielmartin0/Planet ... eplacement
2. Download this debug build of Muluna. https://github.com/nicholasgower/planet ... nated-fuel
3. Start a game with both mods loaded.
4. To test the PlanetsLib entity replacement system on vehicles, place a car on Muluna in cheat mode. It will place correctly, replacing the placed car with a Muluna-exclusive variation with different fuel categories.
5. If desired, test the entity replacement system for static entities by placing a rocket silo on Muluna. It will place correctly, replacing the placed rocket silo with a Muluna-exclusive variation with increased lift weight. Do the same thing with a ghost rocket silo if also desired.
6. On placing any entities that trigger an entity replacement, the game prints two lines: Whether the old entity was an entity-ghost or not, and the arguments passed to surface.create_entity.
7. Place the same car as a ghost. The same entity replacement script will fire as in step 4, but on attempting to place an entity-ghost, the error described above will fire. Read the debug prints made in the game's console. It notes that the detected entity-ghost car is an entity-ghost, and that the newly placed car is also an entity-ghost.

I believe this crash is due to an outdated assertion from before vehicle ghosts were added to the game in 2.0.
Attachments
factorio-current.log
(71.8 KiB) Downloaded 20 times
Rseding91
Factorio Staff
Factorio Staff
Posts: 17242
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.1.12] Erroneous error with surface.create_entity() placing CarPrototype entity ghost

Post by Rseding91 »

Thanks for the report however this is likely a modding error: the car item may be hidden, or have no item-to-place the car. The engine allows making car ghosts without issue. You can confirm this with:

Code: Select all

/c game.player.surface.create_entity{name='entity-ghost', position={1, 0}, force='player', inner_name="car"}
If you want to get ahold of me I'm almost always on Discord.
MeteorSwarm
Inserter
Inserter
Posts: 31
Joined: Thu Sep 25, 2025 10:49 pm
Contact:

Re: [2.1.12] Erroneous error with surface.create_entity() placing CarPrototype entity ghost

Post by MeteorSwarm »

Thank you for the response. I have found the issue with my code, that I was incorrectly searching data.raw.item for vehicle items instead of data.raw["item-with-entity-data"]. Because my code could not confirm that an item with the name of the vehicle existed, it did not assign a placeable_by field. I still believe that this error message should be addressed, because it did not explain the reason why a particular entity could not be placed as a ghost. If the only problem is that I did not define a placeable_by field, that's great to know. Make the error message say that. I should not have to ask a Wube employee for help with understanding an error message. The error should be evident from the error message.
Post Reply

Return to “Modding help”