PDA

View Full Version : Second InventoryManager for pawn occasionally purges itself



Susramanian
01-07-2012, 06:08 PM
I've implemented a second InventoryManager for my pawns which will eventually act as a home inventory, similar to the Item Box in Dungeon Defenders. In testing this, I've run into a bizarre problem: every so often, maybe ten or twenty seconds, the home InventoryManager empties itself. The instance of the InventoryManager is still there, same name and everything. It just loses all inventory items. It doesn't seem to be related to how many things I put in it, or what I do before or afterwards. No more than twenty seconds after anything goes into the home InventoryManager, it disappears. Interestingly, all items disappear at the same time. If I pick up an item every five seconds, I can watch my debug messages in the log confirm the creation of each new inventory item in the home, and watch the counter displaying the number of items tick upwards-- and then, after no more than twenty seconds or so, they all disappear at once. Poof!

I'm stumped. Anybody have an idea of where to look for the cause?

Solid Snake
01-07-2012, 06:32 PM
Did you set the owner of the second InventoryManager to Pawn?

What I can suggest is to subclass InventoryManager, and then override this function like so.



/**
* Discard full inventory, generally because the owner died
*/
simulated event DiscardInventory()
{
ScriptTrace();
Super.DiscardInventory();
}


The ScriptTrace() function is going to tell you all of the functions (excluding native functions) that were called when DiscardInventory is finally called itself. This can help you track down what is going on. If inventory can never be destroyed in the secondary inventory manager, then I suggest just stubbing the DiscardInventory since that is no longer required.

Susramanian
01-07-2012, 08:21 PM
Solid Snake, thank you for the help. I didn't know about ScriptTrace(), and I can see that it's going to be very useful in the future.

I figured it out, and I don't feel too stupid as it was fairly subtle. My DroppedPickups have a SendHome() function that does more or less what the GiveTo() function does, only the item gets put in the home InventoryManager. In my code for SendHome(), I call the InventoryManager's AddInventory() function to put in the new item, then destroy the DroppedPickup. Unfortunately, between using AddInventory() and Destroy(), I neglected to set Inventory = None. The Inventory attached to the DroppedPickup was getting destroyed along with the DroppedPickup, despite showing up in the home's InventoryManager for twenty seconds. All my ScriptTracing() in those twenty seconds were thus turning up nothing, and the InventoryManager was emptying seemingly with no help from the scripts. Turns out the destruction had already happened, and I was looking for it in the wrong time interval.

Bizarre!