Jump to content

Papyrus unable to UnregisterForKey (or Control)?


Hoamaii

Recommended Posts

Am I mistaken to UnregisterForControl - or UnregisterForKey - in an ActiveMagicEffect script?

 

The script compiles fine, and works perfectly in game, but I invariably get log errors saying:

 

"ERROR: Unable to call UnregisterForControl - no native object bound to the script object, or object is of incorrect type stack: [None]._"

 

Same thing with UnregisterForAllKeys() or UnregisterForAllControls().

 

I can't figure out why and it's not much documented in the Wiki - and there's not specific indications about that in SKSE Form.psc or ActiveMagicEffect.psc.

 

Is it because you don't need to Unregister for any of this when used in a Magic Effect script?

 

Is it because I call this onEffectFinish rather than earlier in the script?

 

Thanks!

 

 

Edit: got a partial answer to my own question: no error if calling it OnEffectStart or any other event in the script - I only get errors when calling it onEffectFinish... still can't figure out why though...

Link to comment
Share on other sites

By the time OnEffectFinish runs the script has already become disconnected from the actual magic effect and it was automatically unregistered for you. So yes, you don't need to unregister events on magic effects unless it's a long-running effect and you want to unregister before the effect itself ends for some reason.

Link to comment
Share on other sites

Oh? Thanks, I didn't know that!

 

The script being disconnected from the actual effect - does that mean that it is not safe to call other functions which terminate other events in the onEffectFinish event?

 

Or to be more precise: I call a function in a state event, terminate it in another state, but then created another function in the onEffectFinish event just to make sure that this function terminates properly in case, for some reason (like a key not responding), it did not terminate earlier?..

Link to comment
Share on other sites

Or to be more precise: I call a function in a state event, terminate it in another state, but then created another function in the onEffectFinish event just to make sure that this function terminates properly in case, for some reason (like a key not responding), it did not terminate earlier?..

Your wording's a bit hard to parse. Maybe you could be a bit more detailed about your setup?
Link to comment
Share on other sites

When the script gets to the OnEffectFinish effect the actual magical effect is almost always already gone. That means you can't use "self" and you can't register or unregister for events. If the script has stored values in variables or properties those will still be set and you can use them to manipulate other objects including the spell's target. You can also freely call functions or switch states on the script as long as they aren't trying to manipulate the magic effect in some way. But you don't need to worry about cleaning up the state of the script itself (including unregistering for any events or resetting variables) because as soon as the OnEffectFinish event ends the entire script instance will disappear entirely and everything will be cleaned up automatically by the game.

Link to comment
Share on other sites

Hey thanks to you both, and sorry for my wording, DavidJCobb (that's a Frenchy's English trying to make himself somewhat understood...) - I guess cdcooley has somehow becomes accustomed to it by now :wink:

 

Thanks Cd, you've been helping me quite a few times lately, wish I could kudo you another time!...

 

Ok, I understand what you mean, onEffectFinish is not the place to manipulate the spell itself, like unregister or self.something, or call for updates (not that I do), but any variables used in the main body of the script are still available, like bools or float just to name some.

 

The reason I was asking is somewhere in the main script I may disable parts of PlayerControls for instance and enable them again in another state - or SAE, then restore Default Idle in another - BUT restoring is done using keys input. So, in case keys stop working for some reason, I have added a debug function in my MCM menu to reset the spell (mainly removes it and adds it again later). I figured when that debug function is called, the ActiveMagicEffect event that'll run will be the onEffectFinish, and only that one. I get it now that Unregister will happen automatically when the spell is dispelled but I was not sure enablePlayerControls would for instance - so I added this in the onEffectFinish function too, using a bool varibale like "IsControlDisabled" to check if it's already been called on the main body of the script or not and avoid calling it twice. That's basically it.

 

I've tested that debug and it works as intended with no log error - so I guess I'm ok, right?

 

Thanks again guys, I've learnt something about magic effects events today (good day!) - too bad this kind of precision is not mentionned in the CK wiki - nor SKSE's .psc's for instance - they say you don't need to uregisterForUpdates in AME, but nothing about Keys or Controls.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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