Jump to content

PlaceAtMe and save bloating


LoginToDownload

Recommended Posts

I notice the PlaceAtMe functionality has increased significantly since Oblivion days, including a 'force persistent' variable, but I'm having some trouble finding out what this means for its usage. Does this mean that you can use PlaceAtMe indefinitely without bloating the savegame, so long as Force Persistent remains false? Just for Actors? For everything, from WorldObjects to swords?

 

Thanks to all. My current scripts are piling up references at an uncomfortable rate, and I would love to be able to use forms instead.

Edited by LoginToDownload
Link to comment
Share on other sites

PlaceAtMe will "bloat" your save file either way. It's just a question of how much. The thing about "persistent" objects is that they bloat how much memory they use at run time. (A persistent object stays in memory even if you aren't in the same cell.) Edited by gsmanners
Link to comment
Share on other sites

  • 7 years later...

I recently "found" something i wouldn't expect.
It is about how the game stores values of references that you cast as something else, possibly resulting in creation of unexpected variable references to objects, preventing those objects from being removed from the save after calling Delete(), because something is still referencing those objects.

A simplified realworld example of a script i have:
(this is attached to my custom MiscItem in CK, which is getting frequently spawned by another script using PlaceAtMe())

Scriptname MorsConjuredItem extends objectReference
{attach to a miscItem in CK to make it despawn after some time once it was placed in the world}

effectShader property onUnloadShader auto
{effectShader to play right before despawning}
float property duration = 5.0 auto
{how long before the item despawns}
potion property foodItem auto
{the food item to turn this into when activated}

form miscItem = none
bool doOnce = true

event OnLoad()
    if doOnce
        doOnce = false
        miscItem = self as form ; DO YOU SEE THE PROBLEM? YOU DO? WELL, I DIDNT UNTIL I FOUND THE HARD WAY
        GotoState("LINGER")
        RegisterForSingleUpdate(duration)
    endIf
endEvent

state LINGER
    event OnUpdate()
        GotoState("FADEOUT")
        if Is3DLoaded() && onUnloadShader
            onUnloadShader.Play(self)
        endIf
        RegisterForSingleUpdate(2.5)
    endEvent
endState

state FADEOUT
    event OnUpdate()
        Disable()
        Delete()
        miscItem = none ; SEE THIS? DID YOU KNOW THAT YOU NEED THIS TO PREVENT SAVE FILE BLOAT?
    endEvent
endState

event OnContainerChanged(objectReference _newContainer, objectReference _oldContainer)
    if _newContainer
        UnregisterForUpdate()
        _newContainer.RemoveItem(miscItem, 1, true)
        _newContainer.AddItem(foodItem, 1, true)
        miscItem = none ; HERE IT IS AGAIN. DID YOU REALLY KNOW WHAT WOULD HAPPEN IF YOU WOULDNT DO THIS?
    endIf
endEvent

Do note the lines where i set miscItem to NONE?
It turns out, that if you do...

miscItem = self as form

...the game seem to literally store the value as "reference to the objectReference this script is attached to, but as a form".
In other words, doing the above seems to internally create a reference to the objectReference that script is attached to,
preventing the objRef from being deleted after calling Delete() on it.

I stumbled on this by accident when i checked my save file with Fallrim Tools out of pure curiosity, and saw over 51000 zombie instances of my item script and same number of related refids that never got deleted.
So i recommend using Fallrim Tools from time to time to test what kind of leftovers your mod leaves behind - you may be surprised.

Edited by 5133p39
Link to comment
Share on other sites

  • 2 weeks later...

According to your script above "5133p39" thank you very much.

Good to known that objectReference (actors as well) stored in script "form" variable also suffer from "persistent bug".

 

Best way is to avoid such construct, maybe script as follow:

MorsConjuredItem

 

Scriptname MorsConjuredItem extends ObjectReference
{attach to a miscItem in CK to make it despawn after some time once it was placed in the world}

; https://forums.nexusmods.com/index.php?/topic/578205-placeatme-and-save-bloating/
; 5133p39 wrote: "savegame bloat by using placeatme()"

  Potion PROPERTY foodItem auto                    ; {the food item to turn this into when activated}

  EffectShader PROPERTY onUnloadShader auto        ; {effectShader to play right before despawning}
  Float        PROPERTY duration = 5.0 auto        ; {how long before the item despawns}

  Bool doOnce = TRUE
  Bool bRun                ; [default=False]


; -- EVENTs -- 4

EVENT OnCellDetach()
    bRun = False
ENDEVENT

EVENT OnUnLoad()
    bRun = False
ENDEVENT


EVENT OnLoad()        ; item has 3D ready now
IF ( doOnce )
    bRun   = TRUE
    doOnce = False

    Utility.Wait(duration)               ; How long before the item should play the unload sequence?

    IF ( bRun )
        myF_Effect()
        Utility.Wait(2.5)                ; How long before the item has to despawn finally?
    ENDIF

    IF ( bRun )
        self.Disable()                    ; do it only, if object can be seen
    ENDIF

    self.Delete()    ; mark this object as ready for deletion, objectID will be moved to trashcan queue only
ENDIF
ENDEVENT


EVENT OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
IF ( akNewContainer )
    myF_ItemSwitch(akNewContainer)
ENDIF
ENDEVENT


; -- FUNCTIONs -- 2

;--------------------
FUNCTION myF_Effect()
;--------------------
IF ( onUnloadShader )
    onUnloadShader.Play(self as ObjectReference)
ENDIF
ENDFUNCTION


;--------------------------------------------
FUNCTION myF_ItemSwitch(ObjectReference oRef)
;--------------------------------------------
    oRef.RemoveItem(self as Form,  1, TRUE)
    
    IF ( foodItem )
        oRef.AddItem(foodItem as Form, 1, TRUE)
    ELSE
        Debug.Notification("Missing property foodItem!")
    ENDIF
ENDFUNCTION

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...