Implementation:CARLA simulator Carla ActorAttribute
| Knowledge Sources | |
|---|---|
| Domains | Actor System, RPC Serialization |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
ActorAttribute and ActorAttributeValue are RPC-serializable classes that represent configurable attributes and their values for CARLA actor blueprints.
Description
Defined in the carla::rpc namespace, this file provides two classes:
ActorAttribute represents a full attribute definition including: a string id, an ActorAttributeType (defaulting to Int), a value string, a list of recommended_values, a flag is_modifiable (default true), and restrict_to_recommended (default false). When compiled in UE4 context, it can be constructed from FActorAttribute or FActorVariation types.
ActorAttributeValue is a lightweight version containing only id, type, and value, used when transmitting the selected attribute values rather than the full definition. It can be constructed from an ActorAttribute and supports UE4 conversion to/from FActorAttribute.
Both classes use MSGPACK_DEFINE_ARRAY for serialization.
Usage
Use ActorAttribute when querying available actor blueprints and their configurable parameters. Use ActorAttributeValue when setting specific attribute values during actor spawning.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/rpc/ActorAttribute.h
Signature
namespace carla {
namespace rpc {
class ActorAttribute {
public:
ActorAttribute() = default;
std::string id;
ActorAttributeType type = ActorAttributeType::Int;
std::string value;
std::vector<std::string> recommended_values;
bool is_modifiable = true;
bool restrict_to_recommended = false;
MSGPACK_DEFINE_ARRAY(id, type, value, recommended_values,
is_modifiable, restrict_to_recommended);
};
class ActorAttributeValue {
public:
ActorAttributeValue() = default;
ActorAttributeValue(const ActorAttribute &attribute);
std::string id;
ActorAttributeType type = ActorAttributeType::Int;
std::string value;
MSGPACK_DEFINE_ARRAY(id, type, value);
};
} // namespace rpc
} // namespace carla
Import
#include "carla/rpc/ActorAttribute.h"
I/O Contract
| Field | Type | Default | Description |
|---|---|---|---|
| id | std::string |
empty | Attribute identifier name |
| type | ActorAttributeType |
Int | Data type (Int, Float, String, Bool, etc.) |
| value | std::string |
empty | Current value as string |
| recommended_values | std::vector<std::string> |
empty | List of suggested/allowed values |
| is_modifiable | bool |
true | Whether the attribute can be changed by the user |
| restrict_to_recommended | bool |
false | Whether value must be from recommended_values |
Usage Examples
#include "carla/rpc/ActorAttribute.h"
// Query blueprint attributes
for (const auto &attr : definition.attributes) {
if (attr.id == "color" && attr.is_modifiable) {
// Choose from recommended values
for (const auto &val : attr.recommended_values) {
// e.g., "255,0,0"
}
}
}