You can record all communication between BeamNG.tech and BeamNGpy and save it into files. This records all messages sent using the TCP communication protocol used by BeamNGpy. Both messages to the game engine and to individual vehicles are recorded. Such a recorded session can be later re-played. This can be useful for debugging communication issues or to replay the same communication commands later.
The Lua extension techCapture is used for recording.
tcomCapture.log)
This capture is generated every time you run BeamNG with the -tcom-debug argument and it communicates
with BeamNGpy. It is overwritten every run, so if you want to preserve your recordings, you can create
your custom capture names.
You need to run BeamNG with the -tcom-debug argument and also start the BeamNGpy server. You can choose between launching BeamNG from BeamNGpy,
or by using the command-line arguments to start the BeamNG server.
from beamngpy import BeamNGpy
beamng = BeamNGpy("localhost", 25252, debug=True)
Windows:
Bin64\BeamNG.drive.x64.exe -tcom -tcom-debug -console
Linux:
BinLinux/BeamNG.drive.x64 -tcom -tcom-debug
You need to run BeamNG with the arguments that start the BeamNGpy server. You don’t need to run
it with the -tcom-debug argument in this case. As an alternative, you can launch BeamNG from BeamNGpy
without any extra parameters.
BeamNGpy:
from beamngpy import BeamNGpy
beamng = BeamNGpy("localhost", 25252)
beamng.open()
Windows:
Bin64\BeamNG.drive.x64.exe -tcom -console
Linux:
BinLinux/BeamNG.drive.x64 -tcom
Then, you need to run the following Lua code to start the capture and start logging to the capture file of your choice:
extensions.tech_techCapture.enableRequestCapture('/path/to/outputFilenameWithoutExtension')
After you have start the capture, launch BeamNGpy, record the commands you want, and then close BeamNG and BeamNGpy.
The Lua extension capturePlayer is used for playing back the recorded sessions.
To play a capture, you don’t need to have Python installed or any open TCP connections. Only the capture files created in the previous step are needed.
Start BeamNG (no extra arguments needed).
Run the following Lua code:
extensions.tech_capturePlayer.playCapture('/tcomCapture.GE.log', 'tcomOutput', -1, true)
tech_capturePlayer.playCapture(inputFilename, outputPrefix, dtBetweenRequests, mergeResponses)
inputFilename: The name of the capture. After the first run, the captures from the main socket
and the vehicle sockets are merged, therefore the /tcomCapture.*.log intermediate files get merged into the complete /tcomCapture.log file. Both types of captures are replayable using this function.outputPrefix: The complete path to the output response file without the .log extension. If
nil, then the responses are not logged.dtBetweenRequests: The minimum time (in seconds) between requests that should pass. If it is
set to -1, then the timestamps from the request file are used for calculating the time between
requests.mergeResponses: If true, then the intermediate response files (/tcomOutput.*.log) will get
merged into the complete response file (/tcomOutput.log) after the capture is finished playing.You can check the outputs of the simulator in /tcomOutput.log in the user folder after the capture is finished playing.
Was this article helpful?