Implementation:CARLA simulator Carla World Apply Settings
| Knowledge Sources | |
|---|---|
| Domains | Autonomous Driving Simulation, Real-Time Systems |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for applying simulation configuration parameters to the CARLA world provided by the CARLA simulator.
Description
The World.apply_settings method sends a WorldSettings object to the server, updating the global simulation parameters. This includes toggling synchronous mode, setting a fixed time step, enabling or disabling rendering, and configuring physics substepping. The method returns the frame ID at which the new settings take effect, allowing the client to synchronize its state.
The WorldSettings object acts as a configuration bundle that encapsulates all tunable simulation parameters. Changes are atomic -- the entire settings object is applied at once, preventing inconsistent intermediate states.
Usage
Use this method at the start of a simulation session to configure the desired execution mode, or at runtime to dynamically switch between synchronous and asynchronous operation. It is common practice to store the original settings before modification and restore them during cleanup.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/client/World.cpp - Lines: L56-84
- Python binding:
PythonAPI/carla/src/World.cpp - Lines: L303-306
Signature
World.apply_settings(settings: carla.WorldSettings, timeout: datetime.timedelta = 0) -> int
Import
import carla
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| settings | carla.WorldSettings | Yes | Configuration object containing simulation parameters such as synchronous_mode, fixed_delta_seconds, no_rendering_mode, substepping, max_substep_delta_time, and max_substeps |
| timeout | datetime.timedelta | No | Maximum time to wait for the server to acknowledge the settings change. Defaults to 0 (use the client default timeout). |
Outputs
| Name | Type | Description |
|---|---|---|
| return | int | The frame ID at which the new settings take effect |
Usage Examples
Basic Example
import carla
# Connect and get world
client = carla.Client("localhost", 2000)
client.set_timeout(10.0)
world = client.get_world()
# Save original settings for later restoration
original_settings = world.get_settings()
# Configure synchronous mode with fixed time step
settings = world.get_settings()
settings.synchronous_mode = True
settings.fixed_delta_seconds = 0.05 # 20 FPS simulation rate
# Apply settings and get the frame ID
frame_id = world.apply_settings(settings)
print(f"Settings applied at frame: {frame_id}")
# Run simulation loop
try:
for i in range(100):
world.tick() # Advance simulation by one fixed step
finally:
# Restore original settings on cleanup
world.apply_settings(original_settings)
High-Throughput Training Example
import carla
client = carla.Client("localhost", 2000)
client.set_timeout(10.0)
world = client.get_world()
original_settings = world.get_settings()
# Configure for maximum throughput: synchronous, no rendering, large time step
settings = world.get_settings()
settings.synchronous_mode = True
settings.fixed_delta_seconds = 0.1 # 10 FPS (fewer ticks per second of sim time)
settings.no_rendering_mode = True # Disable GPU rendering
settings.substepping = True
settings.max_substep_delta_time = 0.01
settings.max_substeps = 10
world.apply_settings(settings)
try:
# Training loop runs much faster without rendering overhead
for episode in range(1000):
snapshot = world.tick()
# ... collect observations, compute rewards, apply actions ...
finally:
world.apply_settings(original_settings)