Created
March 25, 2022 18:57
-
-
Save mrowrpurr/d5d291a0b269265dd74dc42309a41d58 to your computer and use it in GitHub Desktop.
SKSE: Bind a script to an object at runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void BindObjectToScript() { | |
ConsoleLog::GetSingleton()->Print("Binding the BindMe script..."); | |
auto* character = PlayerCharacter::GetSingleton(); | |
auto* vm = VirtualMachine::GetSingleton(); | |
auto* handlePolicy = vm->GetObjectHandlePolicy(); | |
auto* bindPolicy = vm->GetObjectBindPolicy(); | |
// Force load the BindMe script | |
vm->linker.Process(BSFixedString("BindMe")); | |
// Get a handle for the character | |
auto handle = handlePolicy->GetHandleForObject(character->GetFormType(), character); | |
// Create an object for this script | |
BSTSmartPointer<Object> objectPtr; | |
vm->CreateObject("BindMe", objectPtr); | |
// Bind it! | |
bindPolicy->BindObject(objectPtr, handle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment