Jump to content

Should I be disabling or deleting these references?


Recommended Posts

Context

I've sorted out the logistics of a mod, where you're able to upgrade or downgrade your workshop machinegun turrets through an activate entry point perk. It's reasonably simple, I pull the orientation of the existing turret, check for the players level, perks, and the current encounter zone. I can then place the new turret at the location of the old turret, correcting the orientation and setting a linked reference to the same workshop (so that the defense value will be recognised by the workshop). Optionally, this process can be repeated for each of the same type of turret using GetWorkshopResourceObject(), assuming that they're loaded (which should be the case).

 

The Problem

The issue is how I go about 'scrapping' the turret that's being replaced. From what I can see there's four alternatives:

  1. Disable()
  2. DisableNoWait()
  3. Delete()
  4. DeleteWhenAble()

I'm aware that you're going to have a bad time if you're deleting things when you're in the CK itself. Is it safe to delete these workshop turrets in-game using scripts, or should I instead settle for disabling them, or go about things entirely differently? I'm hesitant to settle for disabling the turrets, as I assume that disabled references hang around in the memory somewhere, as they have the potential to be re-enabled. If you have a thousand disabled turrets around the place, I imagine that there could be a performance impact. I don't need them to be re-enabled, I just need them gone.

 

Any guidance would be appreciated.

Link to comment
Share on other sites

Never tried what you're specifically trying to do here (on worshop-placed references I mean), but from my experience in Skyrim and FO4, deleting a Vanilla object which has been persistent before and thus somewhat baked in your saves, is never a good idea. I'm not sure how Workshop objects work - do they get deleted when you scrap them or just disabled?

 

For testing purposes, I'd stick with just "Disable()" - it works faster than "DisableNoWait()" in F04 anyway. Or maybe the safest way inside settlements would be to scrap them trhough script instead of disabling them?

 

And the best way to find out how it affects your game is to test it anyway ;)

Link to comment
Share on other sites

I'm unaware whether a workshop object gets disabled and/or deleted when it is scrapped. I just tested it by selecting a reference, scrapping it and attempting to enable it without any luck. Would it be safe to assume that scrapped workshop objects are at the very least not just disabled then? Disabling alone of course removes the turrets respective defense rating from the workshop, though.

 

This thread would indicate that they're placed by scripts, but doesn't reveal much else. I did first look for a Scrap() function or something along those lines, but no luck. The only functions that I'm aware of that allow you to scrap objects are limited to items, and not NPCs (which turrets are).

 

Are you aware of a function that allows you to scrap workshop objects? I may have come across such a function at one point, but I've spent so much time going over the CK wiki that I've forgotten.

 

I'd imagine that disabling turret references would have a very insignificant performance impact (and potentially some save bloat?). I'm concerned with the cumulative impact after however many turrets have been disabled, though. Where it be 1,000, 10,000 or 1,000,000. If there's an impact, I'd almost prefer not to release the mod if it couldn't be avoided.

 

The only turrets that I can think of that would have been in the vanilla game would be those at Covenant before you arrive. I could even find a way to filter those out if they're the only turrets that would cause issues when deleted.

Link to comment
Share on other sites

I don't think there's a scrap function either - at least none listed in the Vanilla functions, I haven't checked if F4SE addresses that.

 

But I was thinking the ones which are potentially "dangerous" to delete for your game are Vanilla ones, not the turrets that your script would be spawning to replace them, assuming that your upgraded turrets forms will be custom ones.

 

If the only way you're ever going to interact with turrets is through the Vanilla workshop UI, can't you simply scrap them in game and create new custom versions of your upgraded turrets? I may not be the best person to help you though as I was not even aware that turrets are NPCs. But if they are, couldn't there be a way to make your turrets Leveled NPCS and add these to the workshop menu?

 

Edit: Yup, just took a quick look at turrets in the CK, better not delete them thru script, they're flagged as essential and their "death" event is when they need to be repaired, so killing them won't work either. I'd suggest you take a close look at their attached scripts and see how you can fit your plans in there.

Link to comment
Share on other sites

The workshop scrapping function actually deletes the object reference. So, anything you can workshop scrap by normal means is safe to Disable() and Delete(). For the use case stated there would be no difference between Disable() and DisableNoWait() with one caveat mentioned next. The only difference is that the script would wait (or not wait) for the disable to finish before resuming execution. You could use Delete() instead of DeleteWhenAble() so long as nothing (scripts) is executing on the object. In which case you should use Disable() not DisableNoWait(). DeleteWhenAble() just waits until the cell gets unloaded to process the delete request.

 

My personal preference is

 

Obj.Disable()

Obj.Delete()

 

You could just as easily use

 

Obj.DisableNoWait()

Obj.DeleteWhenAble()

 

In the end they will accomplish the same thing. Some may argue the latter sequence is "safer" to use. For the use case stated there shouldn't be any reason either one would be unsafe. The second however being non-blocking will execute faster (in the nanoseconds range) but unless you're doing *many* loops of that it's unlikely you'll ever see a performance difference.

Edited by BigAndFlabby
Link to comment
Share on other sites

Thanks for the insight guys. I was in the process of playing around with the KillEssential() function, but there were various reasons as to why that wasn't working as I'd like. By the sounds of it, the second combination that you've suggested is the go. I'd prefer to err on the side of caution, and there will be a number of loops completed if they choose to upgrade all turrets.

 

Could I ask where you found that the scrapping function actually deletes the object reference? Just for future reference, as I have released a number of mods related to the workshop system. I've found that the workshop resources are re-calibrated in the event of an actors death, or when an actor's repaired (in the case of the turret), but not much else. I am still in the process of combing through scripts, so there's obviously things that I would have missed.

 

Thank you everyone for your help :)

Link to comment
Share on other sites

The scrapping from the workshop interface IIRC is done in the engine not a script as opposed to an swf. So you won't find any documentation about it. I don't remember where I saw it. It was a long time ago. You can verify that the scrap deletes the reference ID by having a script set a variable to the reference. Then scrap it. Then have the script try to do something with that variable. It will now come back as a none or invalid (I forget which exactly as I'm too lazy to go write one to test it right now). Simply meaning it no longer exists period. If it was simply being disabled and not deleted then the scripts variable to the object reference would still be valid. Because you could just enable it. There's no logical reason why this would ever happen so it makes sense they would delete it.

 

The engine handles the actors being disabled/unconscious to remove them from the workshop values. This is done because it's substantially faster than trying to have script code detect and manage all of it.

 

Scrapping at a workbench, such as an armor modification one, is handled by the swf actionscript code. That handles detecting the mod attachments and producing appropriate materials for them based on the crafting recipes. The base item still has to have a proper scrap recipe in order to make it produce materials rather than just delete the object.

Edited by BigAndFlabby
Link to comment
Share on other sites

  • Recently Browsing   0 members

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