I just reported that items added to entity slots are not accounted for by the GM (https://feedback.bistudio.com/T171667) but now I found out that items in the hierarchy (e.g. attachments on weapons) are inserted into it, unnecessarily, probably causing a few additional iterations and allocations on a map where many items lay around for longer durations.
This is because, for some reason when a container is moved out of another container onto the ground, the SCR_InventoryStorageManagerComponent::OnItemRemoved does not only trigger for the container but everything it contained too. I was under the impression that the event should only fire for the direct hierarchy root - but hey things be like that. This does, however, adds all the items into the GM even if it would be enough to just store the parent, cause that is the only lifetime that should really tick, and if that is removed all children are deleted anyway. So what is the point in storing the 20 items inside the backpack on the ground too. This is the responsible line: https://enfusionengine.com/api/redirect?to=enfusion://ScriptEditor/Scripts/Game/Inventory/SCR_InventoryStorageManagerComponent.c;407
Instead, I think it could be reworked to use the parent events that will be introduced in an upcoming patch (so they should already be in the dev branch) OnAddedToParent and OnRemovedFromParent. So one of the already scripted components like the inventory item or the inv item storage component could subscribe to those instead. The reason why this will be better is that those events fire for inventory changes that happen on the ground too, where there is no inventorystoragemanager present. And what is neat about using those too is that it would resolve my inital ticket, cause adding an entity that is subscribed to these events to an entity slot through slot manager also fires this generic parent change event. So the GM can be inserted or removed there and work for all systems together. It would also probably remove the need to have the code copy-pasted multiple times for stuff like OnCompartmentEntered etc.