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: Load a vehicle. Nothing happens. No logs from onInit, onPhysicsStep, or updateGFX. Open the console and run my custom function: extensions.my_test_mod.manualTest().The function runs successfully. Immediately after, updateGFX starts firing on every frame, and its log messages begin to appear in the console. 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
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
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/*
Didn't know about enabling physics step, thanks for sharing! This way creating a controller is not necessary.