Implementation:CARLA simulator Carla BlueprintLibrary Filter
| Knowledge Sources | |
|---|---|
| Domains | Autonomous Driving Simulation, Software Design Patterns |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for retrieving the actor blueprint catalog and filtering it by wildcard pattern provided by the CARLA simulator.
Description
World.get_blueprint_library() returns the complete catalog of actor blueprints available in the current simulation session. BlueprintLibrary.filter() returns a new BlueprintLibrary containing only the blueprints whose identifiers match the given wildcard pattern.
The filter uses case-insensitive glob-style matching where * matches any sequence of characters. This allows broad queries like "vehicle.*" (all vehicles) or narrow queries like "sensor.camera.rgb" (one specific sensor). The returned library can be iterated, indexed, or filtered again.
Individual blueprints in the filtered result can then be customized by setting attributes (color, sensor resolution, etc.) before being passed to a spawning function.
Usage
Use get_blueprint_library() and filter() at the beginning of a simulation workflow to discover and select the actor types you want to spawn. This is essential before spawning any vehicle, sensor, or pedestrian.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/client/BlueprintLibrary.h - Lines: L45-46
- Python binding:
PythonAPI/carla/src/Blueprint.cpp - Lines: L101-113
Signature
World.get_blueprint_library() -> carla.BlueprintLibrary
BlueprintLibrary.filter(wildcard_pattern: str) -> carla.BlueprintLibrary
Import
import carla
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| wildcard_pattern | str | Yes | A glob-style pattern to match blueprint identifiers. Use "*" to match all, "vehicle.*" for all vehicles, "sensor.camera.*" for all cameras, etc. Matching is case-insensitive. |
Outputs
| Name | Type | Description |
|---|---|---|
| return (get_blueprint_library) | carla.BlueprintLibrary | The complete catalog of available actor blueprints |
| return (filter) | carla.BlueprintLibrary | A new BlueprintLibrary containing only matching blueprints |
Usage Examples
Basic Example
import carla
import random
client = carla.Client("localhost", 2000)
client.set_timeout(10.0)
world = client.get_world()
# Get the full blueprint library
blueprint_library = world.get_blueprint_library()
print(f"Total blueprints available: {len(blueprint_library)}")
# Filter for all vehicle blueprints
vehicle_blueprints = blueprint_library.filter("vehicle.*")
print(f"Vehicle blueprints: {len(vehicle_blueprints)}")
# Filter for only 4-wheeled vehicles (exclude bikes/motorcycles)
four_wheeled = [bp for bp in vehicle_blueprints
if int(bp.get_attribute("number_of_wheels")) == 4]
# Select a random vehicle blueprint
ego_bp = random.choice(four_wheeled)
print(f"Selected vehicle: {ego_bp.id}")
# Customize the vehicle color
if ego_bp.has_attribute("color"):
ego_bp.set_attribute("color", "255,0,0") # Red
# Set a role name for identification
ego_bp.set_attribute("role_name", "hero")
Sensor Discovery Example
import carla
client = carla.Client("localhost", 2000)
client.set_timeout(10.0)
world = client.get_world()
blueprint_library = world.get_blueprint_library()
# Discover all sensor types
sensor_blueprints = blueprint_library.filter("sensor.*")
print("Available sensors:")
for bp in sensor_blueprints:
print(f" {bp.id}")
for attr in bp:
print(f" {attr.id}: {attr.recommended_values if attr.recommended_values else attr.type}")
# Get a specific camera blueprint and configure it
camera_bp = blueprint_library.find("sensor.camera.rgb")
camera_bp.set_attribute("image_size_x", "1920")
camera_bp.set_attribute("image_size_y", "1080")
camera_bp.set_attribute("fov", "110")
# Get a LiDAR blueprint and configure it
lidar_bp = blueprint_library.find("sensor.lidar.ray_cast")
lidar_bp.set_attribute("channels", "64")
lidar_bp.set_attribute("points_per_second", "1200000")
lidar_bp.set_attribute("rotation_frequency", "20")
lidar_bp.set_attribute("range", "100.0")