Unsolved onPhysicsStep not firing, updateGFX needs a manual "kick" to start

Discussion in 'Mod Support' started by Dix, Aug 22, 2025.

  1. Dix

    Dix
    Expand Collapse

    Joined:
    Jul 19, 2025
    Messages:
    1
    Hello everyone,

    How do I make my mod run at the physics engine's frequency of 2000Hz? The documentation points to onPhysicsStep. However, there's almost no information available about it. It's also not discussed on the forum, nor found in existing mods. I can only get updateGFX to work.
    I am placing my script in the lua/vehicle/extensions/ folder, as the mod should apply to any vehicle that is loaded.

    Essentially, my problems are as follows:

    • onInit and onPhysicsStep are never called automatically. updateGFX is also not called automatically on vehicle spawn.
    • However, updateGFX magically starts working if I manually call any other public function from my mod via the console. It's as if the module is "sleeping" and needs a manual "kick" to get its update loop running.

    How to reproduce the strange behavior:

    1. Load a vehicle. Nothing happens. No logs from onInit, onPhysicsStep, or updateGFX.
    2. Open the console and run my custom function: extensions.my_test_mod.manualTest().The function runs successfully.
    3. Immediately after, updateGFX starts firing on every frame, and its log messages begin to appear in the console.
    4. Despite this, onInit is never called (it seems its one-time trigger is missed), and onPhysicsStep remains inactive.

    This proves that my file path and folder structure are correct. The game loads the file, but fails to properly initialize the event hooks until a manual interaction occurs.

    Here is the simple code I am using for testing:

    - File located at:
    AppData\Local\BeamNG.drive\0.36\mods\unpacked\my_test_mod\lua\vehicle\extensions\auto\controller.lua or
    AppData\Local\BeamNG.drive\0.36\mods\unpacked\my_test_mod\lua\vehicle\extensions\controller.lua
    Code:
    local M = {}
    
    -- This function is NEVER called automatically.
    function M.onInit()
      log("E", "MY_TEST_MOD", "onInit WAS CALLED ")
    end
    
    -- This function is NEVER called automatically.
    function M.onPhysicsStep(dt)
      log("E", "MY_TEST_MOD", " onPhysicsStep IS RUNNING ")
    end
    
    -- This function ONLY starts being called AFTER I run manualTest() from the console.
    function M.updateGFX(dt)
      log("W", "MY_TEST_MOD", "updateGFX is running...")
    end
    
    -- I call this function manually from the console using: extensions.my_test_mod.manualTest()
    function M.manualTest()
      log("I", "MY_TEST_MOD", "manualTest() was called. This should 'wake up' updateGFX.")
    end
    
    return M
    It seems the module is loaded but not fully "activated" or "registered" for automatic callbacks. A manual call seems to finalize some part of this registration process, but only for updateGFX.

    Has anyone seen this behavior before?

    Any help would be greatly appreciated. Thank you
     
    #1 Dix, Aug 22, 2025
    Last edited: Aug 22, 2025
  2. SineMatic

    SineMatic
    Expand Collapse

    Joined:
    Nov 17, 2022
    Messages:
    65
    Hi! This is how I've been doing this.
    To make your GE lua extension load automatically, you can put it in "auto" folder. For example, check this mod: https://www.beamng.com/threads/manual-turn-signal-cancelling.102079/
    Now, regarding 2000 hz stuff. It is only available to vehicles. To make it work, you have to create a vehicle controller and a jbeam part that would use this controller. File path for controller: lua\vehicle\extensions\controller\stuff.lua. Code snippet for jbeam:

    Code:
    "controller":[
            ["fileName"],
            ["stuff", {}],
        ],
    Some code from stuff.lua (as you can see, I used updateFixedStep instead of onPhysicsStep):

    Code:
    local M = {}
    
    local function updateFixedStep(dt)
      -- 2000 hz
    end
    
    local function init()
      print("stuff.lua vehicle controller loaded automatically!")
    end
    
    M.init = init
    M.updateFixedStep = updateFixedStep
    
    return M
     
  3. Neverless

    Neverless
    Expand Collapse

    Joined:
    Sep 18, 2016
    Messages:
    257
    The physics step can be applied and used everywhere in the vehicle vm. You just need to enable it.

    Code:
    local M = {}
    
    M.onExtensionLoaded = function()
        enablePhysicsStepHook() -- enable
    end
    
    M.onPhysicsStep = function(dt) -- now this is run
        print("Hello from physics step")
    end
    
    return M
    Also when you run with the physics step, please ensure your code is not generating much garbage as it can easily lead to stutter. Here is an example.

    And for your extension loading issue, for extensions you want to be auto loaded put it into /lua/vehicle/extensions/auto/*
     
    • Like Like x 1
  4. SineMatic

    SineMatic
    Expand Collapse

    Joined:
    Nov 17, 2022
    Messages:
    65
    Didn't know about enabling physics step, thanks for sharing! This way creating a controller is not necessary.
     
  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