Error using PlatoonApi with BeamNGpy

Hi there!

I was trying to launch a platoon with two vehicles, and I received an error that was hard to debug. I’m running BeamNG in a Docker container with headless mode and connecting to it using BeamNGpy. My Python scripts fail when launching the platoon. Here is the code:

beamng = BeamNGpy(host="127.0.0.1", port=25252)
beamng.open()

scenario = Scenario("west_coast_usa", "vehicle logging")

vehicle1 = Vehicle("leader_vehicle", model="sbr", license="LAINF_1")
vehicle2 = Vehicle("electric_vehicle", model="pickup", license="LAINF_2", part_config='vehicles/sbr/electric_300.pc')

electrics = Electrics()

vehApi = VehiclesApi(beamng)
trafficApi = TrafficApi(beamng)

platoonApi = PlatoonApi(beamng)
platoonApi.launch_platoon(leader=vehicle1, mode="traffic", speed=20, debug=True)
platoonApi.join(leader=vehicle1, veh=vehicle2, speed=20, debug=True)

When I run the script, it fails with the following error:

Traceback (most recent call last):
  File "/opt/BeamNG/BeamNG.tech.v0.36.4.0/testes/explore_vehicle.py", line 212, in <module>
    main()
  File "/opt/BeamNG/BeamNG.tech.v0.36.4.0/testes/explore_vehicle.py", line 55, in main
    platoonApi.launch_platoon(leader=vehicle1, mode="traffic", speed=20, debug=True)
  File "/opt/BeamNG/BeamNG.tech.v0.36.4.0/testes/venv/lib/python3.10/site-packages/beamngpy/api/beamng/platoon.py", line 70, in launch_platoon
    self._send(data).ack("platoonLaunched")
  File "/opt/BeamNG/BeamNG.tech.v0.36.4.0/testes/venv/lib/python3.10/site-packages/beamngpy/connection/connection.py", line 288, in ack
    message = self.recv()
  File "/opt/BeamNG/BeamNG.tech.v0.36.4.0/testes/venv/lib/python3.10/site-packages/beamngpy/connection/connection.py", line 280, in recv
    raise message
beamngpy.logging.BNGError: The request was not handled by BeamNG.tech. This can mean:
- an incompatible version of BeamNG.tech/BeamNGpy
- an internal error in BeamNG.tech
- incorrectly implemented custom command

The container logs do not contain any information related to this error. Here are the last lines of the log:

2.73646|D|GELua.core_modmanager.initDB| Notification : took 61.887923ms to callback
2.73984|D|GELua.gameplay_rawPois.| Raw Poi Lists Cleared. New Generation: 7
2.74001|W|GELua.core_hardwareinfo.core_hwinfo| No desktop entry found. To get a BeamNG entry and (optionally) support for the beamng:// URL scheme, please run the script BinLinux/BeamNG_install_desktop_file.sh.
2.75418|I|GELua.adas_gauge_light.modscript| adas_gauge_light loaded (BeamNG.tech)
2.94919|D|GELua._lua_ge_extensions_gameplay_missions_proceduralMissionGenerators_timeTrialMissions.| Hid 0 prodecural TimeTrials missions because they were hidden by real missions.
2.94979|D|GELua.gameplay_missions_missions.| Loaded 548 total missions: 511 from files, 37 from generators.
3.22707|D|GELua.gameplay_missions_unlocks.| Processed unlock status of missions: 428/548 startable missions, 425/548 visible missions.
3.55064|D|GELua.core_cameraModes_relative.core_camera.relative| No refNodes found, using default fallback
3.58595|E|addBinding| Could not create a description for binding keyboard0::*
3.58733|D|GELua.core_input_bindings.bindings| Loaded 298 bindings for device keyboard0
3.58784|D|GELua.core_input_bindings.bindings| Loaded 20 bindings for device mouse0
21.97896|I|GELua.tech_techCore.TechGE| Accepted new client: 127.0.0.1/46848
22.16230|E|GELua.TechCom| Error reading from socket: closed
22.16235|E|GELua.TechCom| Error reading from socket: tcp{client}: 0x711aa3dded08 - closed

Can anyone help?

Hi @prnascimento,

Thank you for reporting this issue! This is a known bug in BeamNGpy - the launch_platoon() method is missing its Lua handler in BeamNG.tech. Your code is actually correct!

Known Issue:

  • bng.platoon.launch_platoon() - Broken (missing handleLaunchPlatoon handler)
  • This is a maintenance issue that needs to be fixed in the BeamNG.tech codebase

Working Platooning Solution:

Use bng.platoon.load() instead of launch_platoon(). This method works reliably and can handle up to 4 vehicles at once.

# Instead of:
# platoonApi.launch_platoon(leader=vehicle1, mode="traffic", speed=20, debug=True)
# platoonApi.join(leader=vehicle1, veh=vehicle2, speed=20, debug=True)

# Use:
bng.platoon.load(vehicle1, vehicle2, None, None, 20.0, True)

What Works:

  • :white_check_mark: bng.platoon.load() - Create complete platoon
  • :white_check_mark: bng.platoon.join() - Add vehicles to existing platoon
  • :white_check_mark: bng.platoon.leave() - Remove vehicles from platoon
  • :white_check_mark: bng.platoon.join_middle() - Insert vehicles in middle of platoon

Key Points:

  • Your original code was correct - this is a BeamNGpy bug
  • Use bng.platoon.load() as the working alternative

Thanks again for reporting this! It helps the community identify and work around these issues. This should be fixed in future BeamNGpy updates.

Best,
Abdul