[1.1.101] Map editor right-click entity deconstruction doesn't trigger events

Bugs that are actually features.
Locked
User avatar
blargh2015
Inserter
Inserter
Posts: 28
Joined: Sun Jun 03, 2018 3:47 pm
Contact:

[1.1.101] Map editor right-click entity deconstruction doesn't trigger events

Post by blargh2015 »

Note: This is not a repeat of viewtopic.php?p=452117#p452117 - that deals with the deconstruction planner. This is the same type of issue, but in a different mechanism.

I have a mod that numerically tracks the utilization of most entities that produce things (UtilizationMonitorBlargh). As such, it is set to take events on new entities created and destroyed, so it can start tracking on create, and cleanup its data on destroy.

In the map /editor, if you go to None mode, and place down items (assemblers, etc) - the mod gets the entity created signal just fine and does its thing. However, if you right click delete the item, no matching signal on destruction is raised. This means when it's destroyed, I have to rely on an extra entity.valid == true check in my on_tick code to catch this. (Yes, I'm aware occasion mods fail to signal as well but those tend to get fixed quickly, and the entity.valid == true check is relatively expensive compared to the rest of the code - that one check is about 10% of its runtime according to the profiler).

In the thread above, this issue was fixed for the deconstruction planner, but apparently not fixed for manual entity removal. Any chance we can get the same fix there?

Thanks!

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2550
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [1.1.101] Map editor right-click entity deconstruction doesn't trigger events

Post by FuryoftheStars »

From that thread you linked:
Bilka wrote:
Mon Feb 05, 2024 10:58 am
DaveMcW wrote: 2. Enter map editor
3. Make sure Settings -> Instant deconstruction is on.
4. Select Tools -> None.
5. Pick up a deconstruction planner and deconstruct something.
Just to make this clear for anyone coming across this thread: The script_raised_destroy event was only added for the case of instant deconstruction via using a deconstruction planner in the map editor, quoted above.

Destroying an entity by using the "entity" tab in the map editor and "mining" it does NOT raise an event by default (as of writing this post). If you want to be notified of an entity being destroyed via the map editor entity tab, register it for the on_entity_destroyed and listen to the event. This event is raised for any kind of entity destruction (once registered for the entity), including but not limited to using the entity tab in the map editor, chunks or surfaces being removed, or just plain old things like a player mining the entity.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
blargh2015
Inserter
Inserter
Posts: 28
Joined: Sun Jun 03, 2018 3:47 pm
Contact:

Re: [1.1.101] Map editor right-click entity deconstruction doesn't trigger events

Post by blargh2015 »

Yes... and from the API documentation on the on_entity_destroyed event:
Depending on when a given entity is destroyed, this event will be fired at the end of the current tick or at the end of the next tick.
Unfortunately, this makes it useless for my use, as I can still have cases where I haven't gotten the destroy signal in time to remove it from my data before the on_tick runs next, and references an invalid LuaEntity because it's already destroyed, just the signal hasn't gotten to the mod yet. Thus, I still need the expensive valid check.

Just to double check this, I implemented using only the on_entity_destroyed event in the mod (with registering it in the handler for entity creation) and immediately errored out when using other mods that trigger destruction.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2550
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [1.1.101] Map editor right-click entity deconstruction doesn't trigger events

Post by FuryoftheStars »

Unfortunately, due to several factors, not the least of which being that many modders will call .destroy() without setting the raise event true, you should always do the valid check, regardless.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 319
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: [1.1.101] Map editor right-click entity deconstruction doesn't trigger events

Post by Stringweasel »

blargh2015 wrote:
Mon Feb 05, 2024 10:21 pm
(Yes, I'm aware occasion mods fail to signal as well but those tend to get fixed quickly, and the entity.valid == true check is relatively expensive compared to the rest of the code - that one check is about 10% of its runtime according to the profiler).
Not sure how you tested the performance of this call, but the `entity.valid` check should be super cheap performance-wise. Can't remember how it works internally, but I do remember someone with a lot of knowledge saying it's likely one of the cheapest API calls there is.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 319
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: [1.1.101] Map editor right-click entity deconstruction doesn't trigger events

Post by Stringweasel »

For reference, here is the person - who wrote the profiler you used - saying that .valid is the cheapest possible API call.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2550
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [1.1.101] Map editor right-click entity deconstruction doesn't trigger events

Post by FuryoftheStars »

Stringweasel wrote:
Wed Feb 07, 2024 8:50 am
For reference, here is the person - who wrote the profiler you used - saying that .valid is the cheapest possible API call.
As that is in Discord, you may want to screenshot and paste it here for those that don't use Discord.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Loewchen
Global Moderator
Global Moderator
Posts: 8321
Joined: Wed Jan 07, 2015 5:53 pm
Contact:

Re: [1.1.101] Map editor right-click entity deconstruction doesn't trigger events

Post by Loewchen »

If you want to discuss this further, open a modding help topic or make an API request.

Locked

Return to “Not a bug”