Skip to content

Can't get ScriptEngine to work [5.4.22.0] #17

Description

@Dealman

For reference, trying to use this with Valheim. I've added ScriptEngine.dll to the plugins folder and it seems to fire up normally;
[Info : BepInEx] Loading [Script Engine 11.0]

I press F6 to reload the scripts and get these log message (auto-load off, but same result with it on);

[Info   :Script Engine] Loading plugins from C:\Program Files (x86)\Steam\steamapps\common\Valheim\BepInEx\scripts\ValheimTest.dll
[Info   :Script Engine] Unloading old plugin instances
[Info   :Script Engine] Loading plugins from C:\Program Files (x86)\Steam\steamapps\common\Valheim\BepInEx\scripts\ValheimTest.dll

However, neither of my patches are applied and neither does Awake or OnDestroy for the plugin execute. Seems like it simply doesn't do anything, no errors, no warnings, no debug messages.

If I cut and copy ValheimTest.dll from the scripts folder and put it in the plugins folder - it works as expected.

Activity

  1. MeGaGiGaGon commented on Mar 24, 2025

    @MeGaGiGaGon

    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 with HideManagerGameObject = true

  2. ManlyMarco commented on Mar 24, 2025

    @ManlyMarco
    Member

    Probably 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.

  3. Packsolite commented on Sep 23, 2025

    @Packsolite

    Can confirm modding Lethal Company. ScriptEngine is installed and finds the dll in BepInEx/scripts, but the Awake() function of the plugin is never called.

  4. JustArion commented on Dec 16, 2025

    @JustArion

    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...
    
  5. dbidwell94 commented on Dec 27, 2025

    @dbidwell94

    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 /plugins directory works just fine, but /scripts does not work. It sees the mod, but never loads Awake()

    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.

  6. ManlyMarco commented on Dec 27, 2025

    @ManlyMarco
    Member

    Awake will never be called until you press the reload hotkey.

  7. dbidwell94 commented on Dec 28, 2025

    @dbidwell94

    I finally got it to work. I had to put both my compiled dll AAAANNNDDD the *.pdb file in the scripts directory and reload.

    I think this is a good candidate for some documentation improvements :)

  8. JustArion commented on Dec 28, 2025

    @JustArion

    For my case, I had to modify ScriptEngine a bit to handle the case of Chainloader.HideManagerGameObject being true

    tl;dr:

    • Some games can destroy ScriptEngine's root after Awake is called causing Update to never get called (Causing keybinds to just break)
    • When fixed by setting ChainLoader.HideManagerGameObject to 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 scriptManager in ScriptEngine since ReloadPlugins (that recreates scriptManager) is only called during Awake and on Update. This causes a case where scriptManager is 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 LoadDLL doesn't take a GameObject parameter 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
    
  9. dbidwell94 commented on Dec 29, 2025

    @dbidwell94

    Ah yes, this was my case as well. Stationeers modding was the same, needed to modify HideManagerGameObject

  10. ManlyMarco commented on Dec 29, 2025

    @ManlyMarco
    Member

    @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?

  11. dbidwell94 commented on Dec 29, 2025

    @dbidwell94

    I'll have to check later to see if this solves the need for HideManagerGameObject

  12. ManlyMarco commented on Dec 29, 2025

    @ManlyMarco
    Member

    You will still need it enabled in BepInEx.cfg if the game requires it.

  13. JustArion commented on Dec 29, 2025

    @JustArion

    @ManlyMarco I can confirm the PR works on Repo! (Of course given Chainloader.HideManagerGameObject is set to true)

  14. ManlyMarco commented on Jan 1, 2026

    @ManlyMarco
    Member

    Please reopen this issue if the problem persists in some of the games.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions