1. Trouble with the game?
    Try the troubleshooter!

    Dismiss Notice
  2. Issues with the game?
    Check the Known Issues list before reporting!

    Dismiss Notice
  3. Before reporting issues or bugs, please check the up-to-date Bug Reporting Thread for the current version.
    0.36 Bug Reporting thread
    Solutions and more information may already be available.

[Bug] Mods manager deactivate mod button doesnt call 'onExtensionUnloaded' event in the mod

Discussion in 'Troubleshooting: Bugs, Questions and Support' started by Neverless, Mar 7, 2025.

  1. Neverless

    Neverless
    Expand Collapse

    Joined:
    Sep 18, 2016
    Messages:
    242
    Steps to reproduce.
    1. Create simple GE lua extension that has the onExtensionUnloaded event registered and simply put a `print("unload")` into it. modScript.lua should contain `setExtensionUnloadMode("modname", "manual")`
    2. Enable the mod
    3. Try disabling the mod over the mods manager. Function will not be called and as such the print not be printed.

    This behaviour is not true if one does `extensions.unload("modname")`. This is why it makes me think its a bug.

    Sample video


    Code if necessary
    https://github.com/OfficialLambdax/BeamNG-Powerups/blob/alpha_0.5/lua/ge/extensions/PowerUps.lua
     
  2. _N_S_

    _N_S_
    Expand Collapse

    Joined:
    Oct 28, 2017
    Messages:
    76
    Everything is working correctly, why should onExtensionUnloaded be called?
    The module is not unloaded when the mod is deactivated.

    If you need to observe activation or deactivation of a mod, you can use onModDeactivated and onModActivated events.
    And in them if it is necessary to unload the module

    1.png 2.png

    Code:
    local M = {}
    
    M.onExtensionLoaded   = function(...) dump({"onExtensionLoaded",   ...}) end
    M.onExtensionUnloaded = function(...) dump({"onExtensionUnloaded", ...}) end
    
    M.onModManagerReady  = function(...) dump({"onModManagerReady",  ...}) end
    M.onBeforeMountEntry = function(...) dump({"onBeforeMountEntry", ...}) end
    M.onModActivated     = function(...) dump({"onModActivated",     ...}) end
    M.onModDeactivated   = function(...) dump({"onModDeactivated",   ...}) end
    
    return M
     
  3. Neverless

    Neverless
    Expand Collapse

    Joined:
    Sep 18, 2016
    Messages:
    242
    Mod activation calls onExtensionLoaded, why should mod deactivation not call onExtensionUnloaded? seems incohesive.

    If i where to listen to onModDeactivated and filter for my mod name (which ofc the script might simply not know) and then unload myself then the game will still call my scripts events (eg onUpdate).

    Thats why im considering this a bug, listening for anything else but onExtensionUnloaded for unload is only a troubleshoot in my eyes
     
  4. _N_S_

    _N_S_
    Expand Collapse

    Joined:
    Oct 28, 2017
    Messages:
    76
    No, mod activation does not trigger onExtensionLoaded, the mod manager does not take any responsibility for mod content management at all.
    All it does (apart from mounting files) is to execute the modScript.lua file at /scripts/*/modScript.lua, nothing more.
    And then in this file everyone registers their extensions (for example through setExtensionUnloadMode) with the necessary custom events and so on.

    All that is necessary when deactivating a mod, the mod manager does - through the extension system it notifies all “listeners” (via onModDeactivated) that mod {MOD_NAME} has been deactivated.
    And that's good enough. At least for manual unloading of the expansion.
    --- Post updated ---
    And besides, how do you think this should happen?
    How does the mod manager, or well, the extensions system know which module is owned by which mode?
     
  5. Neverless

    Neverless
    Expand Collapse

    Joined:
    Sep 18, 2016
    Messages:
    242
    That extends on what i just said. Activating a mod leads to a call of onExtensionLoaded in said mod (in whatever modules it registers in modScript). Meanwhile deactivating the mod does not lead to onExtensionUnloaded being called in the modules it loads. Thats what i mean when i say its incohesive. I expect it deactivates everything that it loaded, but it doesnt.

    Simple story isnt it? Activate - does activate. Deactivate - does deactivate.
    How exactly the game archives any of that or how the game internally works is nothing that i as the enduser have to care about, because when i as the user click on deactivate, i expect that to happen. Is that a wrong expectation?

    2 Example solutions

    1) The game either keeps track which modules it loaded with which mod and auto unloads them on unload (i dont see why this would be an issue)
    2) Either another function in modScript that eg says `onUnload("myExtensionName")` or another file thats parsed on deactivate that contains the calls to unload.
     
  6. _N_S_

    _N_S_
    Expand Collapse

    Joined:
    Oct 28, 2017
    Messages:
    76
    And how will it differ from manual unloading in onModDeactivated?
    Well, well, I agree that it is probably (at least at first glance) reasonable that deactivating a mod will automatically unload everything that was loaded with it.
    But the realization of such a mechanism does not look trivial. What if, for example, modules had delayed loading, say through jobsystem? Or what to do if some module very much needs to continue working despite deactivation of the mod?
    It is clear that all these issues are solvable in one form or another, but what is it all for? For the sake of not writing 1 line: extensions.unload(“modname”)?

    In my opinion, this is not a bug, but a conscious transfer of responsibility for the module lifetime in the hands of the modder who writes it
    Not very user-friendly, I do not argue, but it can be worked on
     
  7. Neverless

    Neverless
    Expand Collapse

    Joined:
    Sep 18, 2016
    Messages:
    242
    Im not gonna argue your view on it, cause in the end its on us modders to properly work with whats given and not given.However i also find it in the game authors responsibility to ensure that the game acts as a user would expect it. Be that a normal player or a modder. Thats my first issue with this status quo.

    NS your one of the very few lua devs in this community, its actually so few they can be counted on 2 hands to my knowledge. I dont know about you, but i myself get often forced to look at other peoples code and i yet have to see a single that unloads themself through the onModDeactivated event. What i want to say is that to me it seems illogical to not fully unload a mods extensions when the users wishes that to happen (by clicking that button). The sad reality that i observed is that lua mods just dont unload themselfs. Not with onExtensionUnloaded, not with onModDeactivated. They hook to onExtensionLoaded and thats it. And they keep running, not because they want to, but because the author just doesnt know better (or didnt bother). It happens so often that my anti cheat kicks players who still have a lua tire grip mod on, or they joined some server and then mine and some ui's extension or pure lua mod is still active. I see support tickets, people with errors and what not.. all fixed after game restart, fault most likely some lua mod. Not even the example mod by DanielW covers this mechanic btw.

    So the second issue for me is that in my view alot of mods dont properly unload themself, leading to a multitude of bugs. I mean look at the mod this issue here stems from, the PowerUps mods. Enable it, disable it, then catch a powerup. Boom, ge hungup. includes went missing and cant be referenced anymore. Given your reasoning i could argue that yeah hey i didnt want my mod to unload there, but the game did.. partially atleast and now the user can go restart their game.

    Third issue in my eyes is simply that the lua end has barely any documentation. Were all starting modding by looking at each others mods and adapting to it, believing what we see will probably be right, cause its not like that we can go and look it up. We are repeating each others mistakes and inherit each others believes.

    In my eyes transfering the responsibility to the modders while for the first only giving them highly lacking documentation and for the second a extension system that behaves out of expectations seems counterproductive: I mean its not like that `setExtensionUnloadMode("modname", "auto")` solves this issue either. Lua extensions are forced to listen to onModDeactivated in this statue quo and i believe this status quo doesnt help either the modders or the players that are essentially forced to live with a malfunctioning game because something didnt unload as expected. Extensions should be unloaded nonetheless if they listened to any of the events or not.

    If i havent forgotten anything then i think that wraps it up for me. I know that i have no choice but to listen to onModDeactivated for now. Same time i believe this is a problem affecting to many people to not be solved.
     
    #7 Neverless, Jul 8, 2025
    Last edited: Jul 8, 2025
    • Agree Agree x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice