Repository navigation
Can't get ScriptEngine to work [5.4.22.0] #17
Description
Activity
This looks to be a regression from 10.0 to 11.0
I got the same output while trying to get it to work on the Haste Broken Worlds Demo. Downgrading to 10.0 made it work.
Also may or may not be relevant, but on the Haste Broken Worlds Demo it only works withHideManagerGameObject = trueProbably caused by this? 4010d2c#diff-672fb7b075a59ec8b46f434842be7dc30347e9a77acd209cf42a83dfd89ed4ddR168-R169
Maybe the BepInEx version your plugin is built against is not the same as the version the game is running, though it's unlikely to be the cause.The easiest way to find the issue would be for you to attach a debugger and step through the scriptengine reload method.
Can confirm modding Lethal Company. ScriptEngine is installed and finds the dll in
BepInEx/scripts, but theAwake()function of the plugin is never called.I'm having a similar issue but on modding Repo.
[Info :Script Engine] Loading FarawayFriends [Message:Script Engine] Reloaded all plugins!the
Awake()is also never called for the plugin. When I try to reload it via the keybind nothing happens. When I use the FileSystemWatcher instead, I only get this[Info :Script Engine] File FarawayFriends.dll changed. Delayed recompiling...Getting the same issue here for "Stationeers" with BepInEx version 5.4.23.4. Maybe I'm different though as I'm developing on Linux running the game through Proton. Putting my dll in the normal
/pluginsdirectory works just fine, but/scriptsdoes not work. It sees the mod, but never loadsAwake()LogOutput:
[Info : BepInEx] Loading [Script Engine 9.0] [Info :Script Engine] Unloading old plugin instances [Info :Script Engine] Loading plugins from Z:\home\<username>\.local\share\Steam\steamapps\common\Stationeers\BepInEx\scripts\StationeersSlang.dll [Info :Script Engine] Loading com.biddydev.slang [Message:Script Engine] Reloaded all plugins!^^ My
Awake()log is never fired.Awake will never be called until you press the reload hotkey.
I finally got it to work. I had to put both my compiled dll AAAANNNDDD the *.pdb file in the
scriptsdirectory and reload.I think this is a good candidate for some documentation improvements :)
Reacted by ThanhFor my case, I had to modify ScriptEngine a bit to handle the case of
Chainloader.HideManagerGameObjectbeingtruetl;dr:
- Some games can destroy ScriptEngine's root after
Awakeis called causing Update to never get called (Causing keybinds to just break) - When fixed by setting
ChainLoader.HideManagerGameObjectto true loading mods throws a NRE.
In my case, Repo was destroying the BepInEx_Manager after Awake is called. So Update would never get called. Additionally this would destroy the
scriptManagerin ScriptEngine since ReloadPlugins (that recreates scriptManager) is only called during Awake and on Update. This causes a case wherescriptManageris null when trying to add the reloaded mod to scriptManger, throwing a NRE.My solution was modifying the coroutine for loading the dll to be something like this instead:
private GameObject GetOrCreateScriptManager() { if (scriptManager != null) return scriptManager; scriptManager = new GameObject($"ScriptEngine_{DateTime.Now.Ticks}"); DontDestroyOnLoad(scriptManager); return scriptManager; }
Then
LoadDLLdoesn't take aGameObjectparameter anymore, instead we do this:- var instance = obj.AddComponent(type); + var instance = GetOrCreateScriptManager().AddComponent(type);
This prevents the following error:
[Error :Script Engine] Failed to load plugin FarawayFriends because of exception: System.NullReferenceException at (wrapper managed-to-native) UnityEngine.GameObject.Internal_AddComponentWithType(UnityEngine.GameObject,System.Type) at UnityEngine.GameObject.AddComponent (System.Type componentType) [0x00001] in <e4fea505ac6a4f7abd6784308d558cd0>:0 at ScriptEngine.ScriptEngine+<>c__DisplayClass40_2.<LoadDLL>b__1 () [0x0001b] in D:\SVN\BepInEx.Debug\src\ScriptEngine\ScriptEngine.cs:188- Some games can destroy ScriptEngine's root after
Ah yes, this was my case as well.
Stationeersmodding was the same, needed to modifyHideManagerGameObjectReacted by arion@dbidwell94 @JustArion Does this PR fix your issue? #18 You can find builds in the CI output.
It sounds like it's different from the original issue, can anyone test if this makes it function in Valheim and Lethal Company as well?
I'll have to check later to see if this solves the need for
HideManagerGameObjectYou will still need it enabled in BepInEx.cfg if the game requires it.
@ManlyMarco I can confirm the PR works on Repo! (Of course given
Chainloader.HideManagerGameObjectis set to true)- linked a pull request that will close this issue[ScriptEngine] Protect plugin instances with HideAndDontSave #18
on Jan 1, 2026 Please reopen this issue if the problem persists in some of the games.
For reference, trying to use this with Valheim. I've added
ScriptEngine.dllto thepluginsfolder and it seems to fire up normally;[Info : BepInEx] Loading [Script Engine 11.0]I press
F6to reload the scripts and get these log message (auto-load off, but same result with it on);However, neither of my patches are applied and neither does
AwakeorOnDestroyfor the plugin execute. Seems like it simply doesn't do anything, no errors, no warnings, no debug messages.If I cut and copy
ValheimTest.dllfrom the scripts folder and put it in the plugins folder - it works as expected.