Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla Actor Class

From Leeroopedia
Knowledge Sources
Domains Client Library, Actor Management, Simulation
Last Updated 2026-02-15 05:00 GMT

Overview

Actor is the base client-side class representing any entity in the CARLA simulation, providing methods for querying and controlling position, velocity, physics, and lifecycle state.

Description

The Actor class in the carla::client namespace is the foundational class from which all specific actor types (vehicles, walkers, sensors, traffic lights, etc.) inherit. It extends three base classes:

  • EnableSharedFromThis<Actor> -- Enables safe shared pointer creation from this.
  • profiler::LifetimeProfiled -- Tracks actor lifetime for profiling (private inheritance).
  • detail::ActorState -- Provides the underlying state management and episode access.

Query Methods (Non-Simulator Calls)

These methods return data from the last tick without making additional simulator calls:

  • GetLocation() -- Returns the current geom::Location.
  • GetTransform() -- Returns the current geom::Transform (location + rotation).
  • GetVelocity() -- Returns the current 3D velocity as geom::Vector3D.
  • GetAngularVelocity() -- Returns the current 3D angular velocity.
  • GetAcceleration() -- Returns the calculated 3D acceleration.
  • GetActorName() -- Returns the Unreal actor name.
  • GetActorClassName() -- Returns the Unreal class name.
  • GetActorState() -- Returns the rpc::ActorState enum value.

State Checking

  • IsAlive() -- Returns true if the episode is valid and the actor is not PendingKill or Invalid.
  • IsDormant() -- Returns true if the actor state is Dormant.
  • IsActive() -- Returns true if the actor state is Active.

Mutation Methods (Simulator Calls)

  • SetLocation / SetTransform -- Teleport the actor.
  • SetTargetVelocity / SetTargetAngularVelocity -- Set velocity before physics.
  • EnableConstantVelocity / DisableConstantVelocity -- Constant velocity mode.
  • AddImpulse (at center or at location) -- Apply impulse force.
  • AddForce (at center or at location) -- Apply continuous force.
  • AddAngularImpulse / AddTorque -- Apply rotational forces.
  • SetSimulatePhysics / SetCollisions -- Toggle physics and collisions.
  • SetActorDead -- Mark the actor as dead.
  • SetEnableGravity -- Toggle gravity.
  • ApplyTexture -- Apply a color or float-color texture with a material parameter.
  • Destroy() -- Virtual method that requests the simulator to destroy the actor (blocking call).
  • Serialize() -- Returns the actor description for serialization.

Usage

Actor is used as the base type throughout the CARLA client. Users typically work with derived types (Vehicle, Walker, Sensor, TrafficLight) but may use the Actor interface for generic actor operations like positioning and physics control.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/client/Actor.h (161 lines)

Signature

namespace carla {
namespace client {

class Actor
  : public EnableSharedFromThis<Actor>,
    private profiler::LifetimeProfiled,
    public detail::ActorState {

public:
  explicit Actor(ActorInitializer init);
  virtual ~Actor() = default;

  // Query methods (no simulator call)
  geom::Location GetLocation() const;
  geom::Transform GetTransform() const;
  geom::Vector3D GetVelocity() const;
  geom::Vector3D GetAngularVelocity() const;
  geom::Vector3D GetAcceleration() const;
  std::string GetActorName() const;
  std::string GetActorClassName() const;
  rpc::ActorState GetActorState() const;

  bool IsAlive() const;
  bool IsDormant() const;
  bool IsActive() const;

  // Mutation methods (simulator calls)
  void SetLocation(const geom::Location &location);
  void SetTransform(const geom::Transform &transform);
  void SetTargetVelocity(const geom::Vector3D &vector);
  void SetTargetAngularVelocity(const geom::Vector3D &vector);
  void EnableConstantVelocity(const geom::Vector3D &vector);
  void DisableConstantVelocity();
  void AddImpulse(const geom::Vector3D &vector);
  void AddImpulse(const geom::Vector3D &impulse, const geom::Vector3D &location);
  void AddForce(const geom::Vector3D &force);
  void AddForce(const geom::Vector3D &force, const geom::Vector3D &location);
  void AddAngularImpulse(const geom::Vector3D &vector);
  void AddTorque(const geom::Vector3D &vector);
  void SetSimulatePhysics(bool enabled = true);
  void SetCollisions(bool enabled = true);
  void SetActorDead();
  void SetEnableGravity(bool enabled = true);
  virtual bool Destroy();
};

} // namespace client
} // namespace carla

Import

#include "carla/client/Actor.h"

I/O Contract

Inputs

Name Type Required Description
init ActorInitializer Yes Initialization data containing actor description and episode proxy
location geom::Location No Target location for teleportation
transform geom::Transform No Target transform for teleportation with rotation
vector geom::Vector3D No Velocity, impulse, force, or torque vector
enabled bool No Toggle for physics, collisions, gravity, constant velocity

Outputs

Name Type Description
Location geom::Location Current actor location from last tick
Transform geom::Transform Current actor transform from last tick
Velocity geom::Vector3D Current 3D velocity from last tick
ActorState rpc::ActorState Current lifecycle state (Active, Dormant, PendingKill, Invalid)
Destroy result bool Whether destruction was successful

Usage Examples

// Get an actor and query its state
auto actor = world.GetActor(actor_id);
auto location = actor->GetLocation();
auto velocity = actor->GetVelocity();

// Teleport the actor
actor->SetTransform(carla::geom::Transform(
    carla::geom::Location(100.0f, 200.0f, 0.5f),
    carla::geom::Rotation(0.0f, 90.0f, 0.0f)
));

// Apply physics
actor->AddImpulse(carla::geom::Vector3D(0.0f, 0.0f, 1000.0f));
actor->SetSimulatePhysics(true);

// Check state and destroy
if (actor->IsAlive()) {
    actor->Destroy();
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment