Here's the script which is called upon succesfully meeting the soul trap conditions in my magic effect
Spoiler
Function CPSoulTrap(Actor akTarget, Actor akCaster) Debug.StartStackProfiling() float fStart = Utility.GetCurrentRealTime() while Locked Utility.Wait(0.1) endWhile Locked = true int victimlevel = akTarget.GetLevel() bool SoulTrapped if akTarget.HasKeyword(ActorTypeNPC) SoulTrapped = BlackSoul(akTarget, akCaster) elseIf victimlevel >= 38 SoulTrapped = GrandSoul(akCaster) elseIf victimlevel >= 28 && victimlevel <= 37 SoulTrapped = GreaterSoul(akCaster) elseIf victimlevel >= 16 && victimlevel <= 27 SoulTrapped = CommonSoul(akCaster) elseIf victimlevel >= 4 && victimlevel <= 15 SoulTrapped = LesserSoul(akCaster) else SoulTrapped = PettySoul(akCaster) endIf Locked = false if SoulTrapped == true MagMysticismSoulTrapCapture.play(akCaster) SoulTrapTakingImod.apply() SoulTrapPVFX01.Play(akTarget,4.7,akCaster) SoulTrapPVFX02.Play(akCaster,5.9,akTarget) SoulTrapTargetActFXS.Play(akTarget,2) SoulTrapCastActFXS.Play(akCaster,3) endif float fFinish = Utility.GetCurrentRealTime() float fTime = fFinish - fStart Debug.Trace("SOUL TRAP TIME = "+fTime) Debug.StopStackProfiling()endFunctionbool Function BlackSoul(Actor akTarget, Actor akCaster) if akCaster.TrapSoul(akTarget) == true akTarget.AddToFaction(_CPTN_SoulTrappedFaction) return true else return false endIfendFunctionbool Function GrandSoul(Actor akCaster) if GemCheck(akCaster, SoulGemGrand, SoulGemGrandFilled) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, DA01SoulGemAzurasStar, _CPTN_SoulGemAzurasStarGrand) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true else return false endIfendFunctionbool Function GreaterSoul(Actor akCaster) if GemCheck(akCaster, SoulGemGreater, SoulGemGreaterFilled) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, DA01SoulGemAzurasStar, _CPTN_SoulGemAzurasStarGreater) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemGrand, _CPTN_SoulGemGrandGreater) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true else return false endIfendFunctionbool Function CommonSoul(Actor akCaster) if GemCheck(akCaster, SoulGemCommon, SoulGemCommonFilled) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, DA01SoulGemAzurasStar, _CPTN_SoulGemAzurasStarCommon) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemGreater, _CPTN_SoulGemGreaterCommon) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemGrand, _CPTN_SoulGemGrandCommon) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true else return false endIfendFunctionbool Function LesserSoul(Actor akCaster) if GemCheck(akCaster, SoulGemLesser, SoulGemLesserFilled) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, DA01SoulGemAzurasStar, _CPTN_SoulGemAzurasStarLesser) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemCommon, _CPTN_SoulGemCommonLesser) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemGreater, _CPTN_SoulGemGreaterLesser) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemGrand, _CPTN_SoulGemGrandLesser) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true else return false endIfendFunctionbool Function PettySoul(Actor akCaster) if GemCheck(akCaster, SoulGemPetty, SoulGemPettyFilled) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, DA01SoulGemAzurasStar, _CPTN_SoulGemAzurasStarPetty) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemLesser, _CPTN_SoulGemLesserPetty) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemCommon, _CPTN_SoulGemCommonPetty) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemGreater, _CPTN_SoulGemGreaterPetty) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true elseIf GemCheck(akCaster, SoulGemGrand, _CPTN_SoulGemGrandPetty) == true _CPTN_MesSoulTrap.Show() Game.IncrementStat("Souls Trapped") return true else return false endIfendFunctionbool Function GemCheck(Actor akCaster, SoulGem akGem, SoulGem akGemUp) if akCaster.GetItemCount(akGem) > 0 akCaster.RemoveItem(akGem, 1, true) akCaster.AddItem(akGemUp, 1, true) return true else return false endIfendFunction
Here's the stack Profile
Spoiler
Stack_976346 log opened (PC)63395:START:97634663395:POP:976346:2:None:Debug..StartStackProfiling63395:QUEUE_PUSH:976346:2:None:utility.??.GetCurrentRealTime63415:PUSH:976346:2:None:utility..GetCurrentRealTime63415:POP:976346:2:None:utility..GetCurrentRealTime63422:QUEUE_PUSH:976346:2: (02013E40):masterambushscript.??.GetLevel63453:PUSH:976346:2: (02013E40):Actor..GetLevel63453:POP:976346:2: (02013E40):Actor..GetLevel63459:QUEUE_PUSH:976346:2: (02013E40):masterambushscript.??.HasKeyword63488:PUSH:976346:2: (02013E40):Form..HasKeyword63488:POP:976346:2: (02013E40):Form..HasKeyword63489:PUSH:976346:2:_CPTN_CPQ02BlackStarTracker (36022BE9):_cptn_startup..CommonSoul63489:PUSH:976346:3:_CPTN_CPQ02BlackStarTracker (36022BE9):_cptn_startup..GemCheck63489:QUEUE_PUSH:976346:4: (00000014):Actor.??.GetItemCount67013:PUSH:976346:4: (00000014):ObjectReference..GetItemCount67013:POP:976346:4: (00000014):ObjectReference..GetItemCount67016:QUEUE_PUSH:976346:4: (00000014):Actor.??.RemoveItem73405:PUSH:976346:4: (00000014):ObjectReference..RemoveItem73410:POP:976346:4: (00000014):ObjectReference..RemoveItem73410:QUEUE_PUSH:976346:4: (00000014):Actor.??.AddItem77031:PUSH:976346:4: (00000014):ObjectReference..AddItem77035:POP:976346:4: (00000014):ObjectReference..AddItem77035:POP:976346:3:_CPTN_CPQ02BlackStarTracker (36022BE9):_cptn_startup..GemCheck77035:QUEUE_PUSH:976346:3: (3604F173):Message.??.Show77064:PUSH:976346:3: (3604F173):Message..Show77065:POP:976346:3: (3604F173):Message..Show77066:QUEUE_PUSH:976346:3:None:Game.??.IncrementStat77111:PUSH:976346:3:None:Game..IncrementStat77111:POP:976346:3:None:Game..IncrementStat77113:POP:976346:2:_CPTN_CPQ02BlackStarTracker (36022BE9):_cptn_startup..CommonSoul77113:QUEUE_PUSH:976346:2: (00056AC6):Sound.??.Play77144:PUSH:976346:2: (00056AC6):Sound..Play77144:POP:976346:2: (00056AC6):Sound..Play77145:QUEUE_PUSH:976346:2:SoulTrapTakingImod (00054225):ImageSpaceModifier.??.Apply77201:PUSH:976346:2:SoulTrapTakingImod (00054225):ImageSpaceModifier..Apply77201:POP:976346:2:SoulTrapTakingImod (00054225):ImageSpaceModifier..Apply77201:QUEUE_PUSH:976346:2: (000531AF):VisualEffect.??.Play77201:PUSH:976346:2: (000531AF):VisualEffect..Play77201:POP:976346:2: (000531AF):VisualEffect..Play77204:QUEUE_PUSH:976346:2: (000531B1):VisualEffect.??.Play77257:PUSH:976346:2: (000531B1):VisualEffect..Play77257:POP:976346:2: (000531B1):VisualEffect..Play77259:QUEUE_PUSH:976346:2: (00054223):EffectShader.??.Play77272:PUSH:976346:2: (00054223):EffectShader..Play77273:POP:976346:2: (00054223):EffectShader..Play77276:QUEUE_PUSH:976346:2: (00054224):EffectShader.??.Play77331:PUSH:976346:2: (00054224):EffectShader..Play77331:POP:976346:2: (00054224):EffectShader..Play77331:QUEUE_PUSH:976346:2:None:utility.??.GetCurrentRealTime77382:PUSH:976346:2:None:utility..GetCurrentRealTime77382:POP:976346:2:None:utility..GetCurrentRealTime77382:PUSH:976346:2:None:Debug..Trace77384:POP:976346:2:None:Debug..Trace77384:PUSH:976346:2:None:Debug..StopStackProfiling77384:DONE:976346Log closed
Most notably though is this...
63489:QUEUE_PUSH:976346:4: (00000014):Actor.??.GetItemCount67013:PUSH:976346:4: (00000014):ObjectReference..GetItemCount67013:POP:976346:4: (00000014):ObjectReference..GetItemCount67016:QUEUE_PUSH:976346:4: (00000014):Actor.??.RemoveItem73405:PUSH:976346:4: (00000014):ObjectReference..RemoveItem73410:POP:976346:4: (00000014):ObjectReference..RemoveItem73410:QUEUE_PUSH:976346:4: (00000014):Actor.??.AddItem77031:PUSH:976346:4: (00000014):ObjectReference..AddItem77035:POP:976346:4: (00000014):ObjectReference..AddItem
3.5 seconds to call GetItemCount on the player, 6.4 seconds for RemoveItem, and 3.6 seconds for RemoveItem. So if I did my math correctly, ~13.5 seconds out of 14.0 is being spent waiting to call the functions on the Player which is absolutely ridiculous. Is there anything I can do to solve this issue? I'm running this with other mods on, and I think the script is only slow when the Player is in an exterior cell. Is there a way to see what exactly is holding up my script?