Hi altogether,
when I use "remove all entities" in editor mode, it seems so that there is no event triggered for that.
Although it's obvious that there can't / shouldn't be an event for each entity removed from a surface, i would expect that at least one event is triggered for this action to have a chance to react to it - IMO on_surface_cleared (which is raised when importing a save file) would be fine.
Is the absence of any event really intended behaviour?
No event is raised when using "remove all entities" in editor mode
Re: No event is raised when using "remove all entities" in editor mode
Yes. You can use https://lua-api.factorio.com/latest/cla ... _destroyed
If you want to get ahold of me I'm almost always on Discord.
Re: No event is raised when using "remove all entities" in editor mode
Hmm - sounds a bit weird - and quite cumbersomeRseding91 wrote: Mon Oct 20, 2025 11:10 am Yes. You can use https://lua-api.factorio.com/latest/cla ... _destroyed
Thx for your quick answer
Re: No event is raised when using "remove all entities" in editor mode
There are many ways for entities to go away without an explicit event. The above link handles them all guaranteed.
If you want to get ahold of me I'm almost always on Discord.
Re: No event is raised when using "remove all entities" in editor mode
This is also the reason that checking any stored Lua object references for .valid==true before use is important even if you don't think it should have changed. Editor causes multiple things to happen that don't in normal gameplay.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: No event is raised when using "remove all entities" in editor mode
Ah - didn't see at first that it is possible to register the surface itself with https://lua-api.factorio.com/latest/cla ... _destroyed - and that is what I need 
Re: No event is raised when using "remove all entities" in editor mode
You can use on_surface_deleted and on_surface_cleared for surface deletions or calls to LuaSurface.clear.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: No event is raised when using "remove all entities" in editor mode
Sorry - my fault. Didn't double check the usability of registering the surface itself with https://lua-api.factorio.com/latest/cla ... _destroyed for my problem. I had overlooked that using "remove all entities" in editor mode doesn't delete the surface at all
.
So registering all relevant entities on the surface with https://lua-api.factorio.com/latest/cla ... _destroyed is a valid solution - although not my favorite
And the lack of any event being risen by the usage of "remove all entities" is the core of my problem - if on_surface_cleared would be risen when using it, everything would be fine and convenient.Bilka wrote: Mon Oct 20, 2025 12:41 pm You can use on_surface_deleted and on_surface_cleared for surface deletions or calls to LuaSurface.clear.
So registering all relevant entities on the surface with https://lua-api.factorio.com/latest/cla ... _destroyed is a valid solution - although not my favorite
Re: No event is raised when using "remove all entities" in editor mode
You'll get the same behavior if any mod simply calls destroy() on anything, or if someone enters a simple command such as:
Code: Select all
for _,v in pairs(game.player.surface.find_entities_filtered{}) do
v.destroy()
endIf you want to get ahold of me I'm almost always on Discord.
Re: No event is raised when using "remove all entities" in editor mode
A good hint - I hadn't noticed that yet. Thx for the clarificationRseding91 wrote: Mon Oct 20, 2025 2:08 pm You'll get the same behavior if any mod simply calls destroy() on anything, or if someone enters a simple command such as:
Code: Select all
for _,v in pairs(game.player.surface.find_entities_filtered{}) do v.destroy() end
P.S.: Such nasty mods should be forbidden


