Skip to content
alexdunn edited this page Sep 8, 2014 · 1 revision

For some mods you'll want to store information about each specific instance of an object. For example, you might want to track the durability of each tent a player owns or which soul was captured in which soul gem. There are several ways to achieve this.

Method 1: Quest Aliases using the Story Manager

Method 2: Unique Object References

The above method has the advantage that you can attach scripts, packages, keywords, and everything else offered in a Quest Alias. However, it can be very unwieldy when you need to keep track of many items. For example, trying to keep track of every soul gem the player uses. It could potentially be hundreds.

  • First, you'll need to create an ObjectReference that is persistent. You can do this with the PlaceAtMe method:
ObjectReference newPersistentRef = myTargetMarker.PlaceAtMe(myObjectForm, 1, true, true)

That third parameter set to true will make the created ObjectReference have a unique ID that will never change.

  • Store that unique ID somewhere. You could store it in a Papyrus Array, but you'll have a limit of 128 items. It may be both easier and better to use JContainers because you have no size limits and you can store both this unique ID and the information you want to track right along with each other.
  • Also store whatever information you are tracking in an Array in the same location, or even better, in a map with JContainers.
  • Later, when your ObjectReference is used somewhere, you can test its ID and then retrieve the information you need based on that:
Int id = myObjectReference.GetFormID()
Int idLocation = myStoredIDsArray.Find(id)
myStoredTrackingInfoArray[idLocation]

This method has the drawback that it requires the object references to be persistent. That is, the reference to each item you create will always be in memory.