Knowing That a Persistent ObjectReference Has Been Destroyed

Post » Thu Sep 11, 2014 2:52 pm

I am storing information about various ObjectReferences in JContainers. I need to be able to remove them from JContainers once they've been used up. For example, when a player consumes one of the ObjectReferences.

Unfortunately, it's not possible for me to know when when one of these items is used up. For example, when a soul gem is used at the enchanting workbench, neither a Story Event Player Remove Item is fired, nor is an OnPlayerRemoveItem event fired.

So, I've got to go about it in a more indirect manner. I was hoping I could call some function on the object ID of a persistent ObjectReference. If the object exists, then it'll return that object. If it doesn't exist, then it will return None.

Unfortunately, Game.GetForm() always returns None when I pass it the ID of a persistent ObjectReference. This makes sense because it's meant to find Forms rather than ObjectReferences.

Any ideas on how I might know that an object I'm tracking is no longer in the game?

User avatar
Breautiful
 
Posts: 3539
Joined: Tue Jan 16, 2007 6:51 am

Post » Thu Sep 11, 2014 2:43 pm

Game.GetForm() will fail for object references or form IDs greater than 7FFFFFFF. All player created potions and many other items (most likely including filled soul gems but I didn't test those) can't be returned by GetForm. You could try the SKSE function GetFormEx but I'm not sure that's going to solve your problem.If it is really a persistent ObjectReference then it has to be in the game. The item may no longer be in the player's inventory, but it is either still in memory somewhere or you've managed to create the ugly problem which leaves a script object disconnected from the game object it is supposed to represent.
User avatar
Austin Suggs
 
Posts: 3358
Joined: Sun Oct 07, 2007 5:35 pm

Post » Thu Sep 11, 2014 3:29 pm

GetFormEx didn't help, unfortunately. Thanks for the idea.

I am not holding any references to these objects in any scripts. When the game removes its own references to the object, it should be freed from memory.

I am simply storing the objects' IDs in JContainers. JContainers doesn't affect the memory management of objects in the game. However, leaving unused data in JContainers is bad because it will always remain in the save file and it will make the JContainers database larger when it's in memory (the whole game). I think this is closer to your second option of when my stored representation is disconnected from any game object. In the situation I describe, there will be no game object. I am searching for a means to discover this so that I can purge it from the JContainers database.

User avatar
Sabrina Schwarz
 
Posts: 3538
Joined: Fri Jul 14, 2006 10:02 am


Return to V - Skyrim