Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mrowrpurr/d5d291a0b269265dd74dc42309a41d58 to your computer and use it in GitHub Desktop.
Save mrowrpurr/d5d291a0b269265dd74dc42309a41d58 to your computer and use it in GitHub Desktop.
SKSE: Bind a script to an object at runtime
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