239 BIND_SYNC(get_traffic_manager_running) << [
this] (uint16_t port) ->
R<std::pair<std::string, uint16_t>>
243 return std::pair<std::string, uint16_t>(it->second, it->first);
245 return std::pair<std::string, uint16_t>(
"",0);
249 BIND_SYNC(add_traffic_manager_running) << [
this] (std::pair<std::string, uint16_t> trafficManagerInfo) ->
R<bool>
251 uint16_t port = trafficManagerInfo.second;
255 std::pair<uint16_t, std::string>(port, trafficManagerInfo.first));
275 return carla::version();
290 BIND_ASYNC(get_available_maps) << [
this]() ->
R<std::vector<std::string>>
294 std::vector<std::string> result;
297 result.reserve(MapNames.Num());
299 for (
const auto &MapName : MapNames)
301 if (MapName.Contains(
"/Sublevels/"))
303 if (MapName.Contains(
"/BaseMap/"))
305 if (MapName.Contains(
"/BaseLargeMap/"))
307 if (MapName.Contains(
"_Tile_"))
311 result.emplace_back(cr::FromFString(MapName));
317 BIND_SYNC(load_new_episode) << [
this](
const std::string &map_name,
const bool reset_settings, cr::MapLayer MapLayers) ->
R<void>
326 GameInstance->
SetMapLayer(
static_cast<int32
>(MapLayers));
328 if(!
Episode->LoadNewEpisode(cr::ToFString(map_name), reset_settings))
330 FString Str(TEXT(
"Map '"));
331 Str += cr::ToFString(map_name);
332 Str += TEXT(
"' not found");
371 BIND_SYNC(copy_opendrive_to_file) << [
this](
const std::string &opendrive, cr::OpendriveGenerationParameters Params) ->
R<void>
377 if (!
Episode->LoadNewOpendriveEpisode(cr::ToLongFString(opendrive), Params))
384 BIND_SYNC(apply_color_texture_to_objects) << [
this](
385 const std::vector<std::string> &actors_name,
386 const cr::MaterialParameter& parameter,
387 const cr::TextureColor& Texture) ->
R<void>
398 TArray<AActor*> ActorsToPaint;
399 for(
const std::string& actor_name : actors_name)
404 ActorsToPaint.Add(ActorToPaint);
408 if(!ActorsToPaint.Num())
415 for(
AActor* ActorToPaint : ActorsToPaint)
425 BIND_SYNC(apply_float_color_texture_to_objects) << [
this](
426 const std::vector<std::string> &actors_name,
427 const cr::MaterialParameter& parameter,
428 const cr::TextureFloatColor& Texture) ->
R<void>
436 TArray<AActor*> ActorsToPaint;
437 for(
const std::string& actor_name : actors_name)
442 ActorsToPaint.Add(ActorToPaint);
446 if(!ActorsToPaint.Num())
453 for(
AActor* ActorToPaint : ActorsToPaint)
463 BIND_SYNC(get_names_of_all_objects) << [
this]() ->
R<std::vector<std::string>>
472 std::vector<std::string> NamesStd;
473 for (
const FString &Name : NamesFString)
475 NamesStd.emplace_back(cr::FromFString(Name));
492 const auto &SpawnPoints =
Episode->GetRecommendedSpawnPoints();
494 FString MapDir = FullMapPath.RightChop(FullMapPath.Find(
"Content/", ESearchCase::CaseSensitive) + 8);
495 MapDir +=
"/" +
Episode->GetMapName();
497 cr::FromFString(MapDir),
498 MakeVectorFromTArray<cg::Transform>(SpawnPoints)};
507 BIND_SYNC(get_navigation_mesh) << [
this]() ->
R<std::vector<uint8_t>>
512 std::vector<uint8_t> Result(FileContents.Num());
513 memcpy(&Result[0], FileContents.GetData(), FileContents.Num());
517 BIND_SYNC(get_required_files) << [
this](std::string folder =
"") ->
R<std::vector<std::string>>
522 if (folder[folder.size() - 1] !=
'/' && folder[folder.size() - 1] !=
'\\') {
529 const auto folderDir = mapDir +
"/" + folder.c_str();
530 const auto fileName = mapDir.EndsWith(
Episode->GetMapName()) ?
"*" :
Episode->GetMapName();
533 TArray<FString> Files;
534 IFileManager::Get().FindFilesRecursive(Files, *folderDir, *(fileName +
".xodr"),
true,
false,
false);
535 IFileManager::Get().FindFilesRecursive(Files, *folderDir, *(fileName +
".bin"),
true,
false,
false);
538 std::vector<std::string> result;
539 for (
auto File : Files) {
540 File.RemoveFromStart(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
541 result.emplace_back(TCHAR_TO_UTF8(*File));
546 BIND_SYNC(request_file) << [
this](std::string name) ->
R<std::vector<uint8_t>>
551 FString path(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
552 path.Append(name.c_str());
555 TArray<uint8_t> Content;
556 FFileHelper::LoadFileToArray(Content, *path, 0);
557 std::vector<uint8_t> Result(Content.Num());
558 memcpy(&Result[0], Content.GetData(), Content.Num());
566 return cr::EpisodeSettings{
Episode->GetSettings()};
569 BIND_SYNC(set_episode_settings) << [
this](
570 const cr::EpisodeSettings &settings) ->
R<uint64_t>
573 Episode->ApplySettings(settings);
590 BIND_SYNC(get_actor_definitions) << [
this]() ->
R<std::vector<cr::ActorDefinition>>
593 return MakeVectorFromTArray<cr::ActorDefinition>(
Episode->GetActorDefinitions());
604 return Episode->SerializeActor(CarlaActor);
607 BIND_SYNC(get_all_level_BBs) << [
this](uint8 QueriedTag) ->
R<std::vector<cg::BoundingBox>>
610 TArray<FBoundingBox> Result;
620 for(
auto& Box : Result)
625 return MakeVectorFromTArray<cg::BoundingBox>(Result);
628 BIND_SYNC(get_environment_objects) << [
this](uint8 QueriedTag) ->
R<std::vector<cr::EnvironmentObject>>
640 for(
auto& Object : Result)
645 return MakeVectorFromTArray<cr::EnvironmentObject>(Result);
648 BIND_SYNC(enable_environment_objects) << [
this](std::vector<uint64_t> EnvObjectIds,
bool Enable) ->
R<void>
657 TSet<uint64> EnvObjectIdsSet;
658 for(uint64 Id : EnvObjectIds)
660 EnvObjectIdsSet.Emplace(Id);
672 auto *Weather =
Episode->GetWeather();
673 if (Weather ==
nullptr)
677 return Weather->GetCurrentWeather();
680 BIND_SYNC(set_weather_parameters) << [
this](
681 const cr::WeatherParameters &weather) ->
R<void>
684 auto *Weather =
Episode->GetWeather();
685 if (Weather ==
nullptr)
689 Weather->ApplyWeather(weather);
699 if (GameMode ==
nullptr)
701 RESPOND_ERROR(
"get_imui_gravity error: unable to get carla gamemode");
710 if (GameMode ==
nullptr)
712 RESPOND_ERROR(
"get_imui_gravity error: unable to get carla gamemode");
721 const std::vector<FCarlaActor::IdType> &ids) ->
R<std::vector<cr::Actor>>
725 std::vector<cr::Actor> Result;
726 Result.reserve(ids.size());
728 for (
auto &&Id : ids)
733 Result.emplace_back(
Episode->SerializeActor(View));
740 cr::ActorDescription Description,
746 auto Result =
Episode->SpawnActorWithInfo(Transform, std::move(Description));
748 if (Result.Key != EActorSpawnResultStatus::Success)
750 UE_LOG(LogCarla, Error, TEXT(
"Actor not Spawned"));
760 return Episode->SerializeActor(Result.Value);
763 BIND_SYNC(spawn_actor_with_parent) << [
this](
764 cr::ActorDescription Description,
765 const cr::Transform &Transform,
766 cr::ActorId ParentId,
767 cr::AttachmentType InAttachmentType,
774 auto Result =
Episode->SpawnActorWithInfo(Transform, std::move(Description));
776 if (Result.Key != EActorSpawnResultStatus::Success)
789 if (!ParentCarlaActor)
791 RESPOND_ERROR(
"unable to attach actor: parent actor not found");
798 #if defined(WITH_ROS2)
800 if (ROS2->IsEnabled())
807 if (Attr.Key ==
"ros_name")
809 const std::string value = std::string(TCHAR_TO_UTF8(*Attr.Value.Value));
810 ROS2->AddActorParentRosName(
static_cast<void*
>(CarlaActor->
GetActor()),
static_cast<void*
>(CurrentActor->
GetActor()));
825 FString(socket_name.c_str()));
832 return Episode->SerializeActor(CarlaActor);
843 UE_LOG(LogCarla, Log, TEXT(
"CarlaServer destroy_actor %d"), ActorId);
846 if (!
Episode->DestroyActor(ActorId))
856 APlayerController* PController= UGameplayStatics::GetPlayerController(
Episode->GetWorld(), 0);
859 auto result = PController->ConsoleCommand(UTF8_TO_TCHAR(cmd.c_str()),
true);
861 result.Contains(FString(TEXT(
"Command not recognized"))) ||
862 result.Contains(FString(TEXT(
"Error")))
865 return GEngine->Exec(
Episode->GetWorld(), UTF8_TO_TCHAR(cmd.c_str()));
872 bool ForceInPrimary =
false;
877 ForceInPrimary =
true;
881 FString Desc =
Episode->GetActorDescriptionFromStream(sensor_id);
882 if (Desc ==
"" || Desc ==
"sensor.other.collision")
884 ForceInPrimary =
true;
890 UE_LOG(LogCarla, Log, TEXT(
"Sensor %d '%s' created in secondary server"), sensor_id, *Desc);
896 UE_LOG(LogCarla, Log, TEXT(
"Sensor %d '%s' created in primary server"), sensor_id, *Desc);
905 bool ForceInPrimary =
false;
910 ForceInPrimary =
true;
914 FString Desc =
Episode->GetActorDescriptionFromStream(sensor_id);
915 if (Desc ==
"" || Desc ==
"sensor.other.collision")
917 ForceInPrimary =
true;
937 bool ForceInPrimary =
false;
942 ForceInPrimary =
true;
946 FString Desc =
Episode->GetActorDescriptionFromStream(sensor_id);
947 if (Desc ==
"" || Desc ==
"sensor.other.collision")
949 ForceInPrimary =
true;
969 bool ForceInPrimary =
false;
974 ForceInPrimary =
true;
978 FString Desc =
Episode->GetActorDescriptionFromStream(sensor_id);
979 if (Desc ==
"" || Desc ==
"sensor.other.collision")
981 ForceInPrimary =
true;
999 std::string message) ->
R<void>
1008 " Actor Id: " + FString::FromInt(ActorId));
1016 " Actor Id: " + FString::FromInt(ActorId));
1024 " Actor Id: " + FString::FromInt(ActorId));
1027 Sensor->
Send(cr::ToFString(message));
1033 BIND_SYNC(set_actor_location) << [
this](
1034 cr::ActorId ActorId,
1035 cr::Location Location) ->
R<void>
1042 "set_actor_location",
1044 " Actor Id: " + FString::FromInt(ActorId));
1048 Location, ETeleportType::TeleportPhysics);
1052 BIND_SYNC(set_actor_transform) << [
this](
1053 cr::ActorId ActorId,
1054 cr::Transform Transform) ->
R<void>
1061 "set_actor_transform",
1063 " Actor Id: " + FString::FromInt(ActorId));
1067 Transform, ETeleportType::TeleportPhysics);
1072 cr::ActorId ActorId,
1073 cr::Transform Transform,
1083 " Actor Id: " + FString::FromInt(ActorId));
1097 " Actor Id: " + FString::FromInt(ActorId));
1104 BIND_SYNC(set_actor_target_velocity) << [
this](
1105 cr::ActorId ActorId,
1106 cr::Vector3D vector) ->
R<void>
1113 "set_actor_target_velocity",
1115 " Actor Id: " + FString::FromInt(ActorId));
1122 "set_actor_target_velocity",
1124 " Actor Id: " + FString::FromInt(ActorId));
1129 BIND_SYNC(set_actor_target_angular_velocity) << [
this](
1130 cr::ActorId ActorId,
1131 cr::Vector3D vector) ->
R<void>
1138 "set_actor_target_angular_velocity",
1140 " Actor Id: " + FString::FromInt(ActorId));
1147 "set_actor_target_angular_velocity",
1149 " Actor Id: " + FString::FromInt(ActorId));
1154 BIND_SYNC(enable_actor_constant_velocity) << [
this](
1155 cr::ActorId ActorId,
1156 cr::Vector3D vector) ->
R<void>
1163 "enable_actor_constant_velocity",
1165 " Actor Id: " + FString::FromInt(ActorId));
1173 "enable_actor_constant_velocity",
1175 " Actor Id: " + FString::FromInt(ActorId));
1181 BIND_SYNC(disable_actor_constant_velocity) << [
this](
1182 cr::ActorId ActorId) ->
R<void>
1189 "disable_actor_constant_velocity",
1191 " Actor Id: " + FString::FromInt(ActorId));
1199 "disable_actor_constant_velocity",
1201 " Actor Id: " + FString::FromInt(ActorId));
1208 cr::ActorId ActorId,
1209 cr::Vector3D vector) ->
R<void>
1216 "add_actor_impulse",
1218 " Actor Id: " + FString::FromInt(ActorId));
1226 "add_actor_impulse",
1228 " Actor Id: " + FString::FromInt(ActorId));
1233 BIND_SYNC(add_actor_impulse_at_location) << [
this](
1234 cr::ActorId ActorId,
1235 cr::Vector3D impulse,
1236 cr::Vector3D location) ->
R<void>
1243 "add_actor_impulse_at_location",
1245 " Actor Id: " + FString::FromInt(ActorId));
1247 FVector UELocation = location.ToCentimeters().ToFVector();
1259 "add_actor_impulse_at_location",
1261 " Actor Id: " + FString::FromInt(ActorId));
1268 cr::ActorId ActorId,
1269 cr::Vector3D vector) ->
R<void>
1278 " Actor Id: " + FString::FromInt(ActorId));
1281 CarlaActor->
AddActorForce(vector.ToCentimeters().ToFVector());
1287 " Actor Id: " + FString::FromInt(ActorId));
1292 BIND_SYNC(add_actor_force_at_location) << [
this](
1293 cr::ActorId ActorId,
1295 cr::Vector3D location) ->
R<void>
1302 "add_actor_force_at_location",
1304 " Actor Id: " + FString::FromInt(ActorId));
1306 FVector UELocation = location.ToCentimeters().ToFVector();
1318 "add_actor_force_at_location",
1320 " Actor Id: " + FString::FromInt(ActorId));
1325 BIND_SYNC(add_actor_angular_impulse) << [
this](
1326 cr::ActorId ActorId,
1327 cr::Vector3D vector) ->
R<void>
1334 "add_actor_angular_impulse",
1336 " Actor Id: " + FString::FromInt(ActorId));
1343 "add_actor_angular_impulse",
1345 " Actor Id: " + FString::FromInt(ActorId));
1351 cr::ActorId ActorId,
1352 cr::Vector3D vector) ->
R<void>
1361 " Actor Id: " + FString::FromInt(ActorId));
1370 " Actor Id: " + FString::FromInt(ActorId));
1375 BIND_SYNC(get_actor_component_world_transform) << [
this](
1376 cr::ActorId ActorId,
1384 "get_actor_component_world_transform",
1386 " Actor Id: " + FString::FromInt(ActorId));
1390 TArray<UActorComponent*> Components;
1391 CarlaActor->
GetActor()->GetComponents(Components);
1393 USceneComponent* Component =
nullptr;
1394 for(
auto Cmp : Components)
1396 if(USceneComponent* SCMP = Cast<USceneComponent>(Cmp))
1398 if(SCMP->GetName() == componentName.c_str())
1409 "get_actor_component_world_transform",
1411 " Component Name: " + FString(componentName.c_str()));
1414 FTransform ComponentWorldTransform = Component->GetComponentTransform();
1415 return cr::Transform(ComponentWorldTransform);
1419 BIND_SYNC(get_actor_component_relative_transform) << [
this](
1420 cr::ActorId ActorId,
1428 "get_actor_component_relative_transform",
1430 " Actor Id: " + FString::FromInt(ActorId));
1434 TArray<UActorComponent*> Components;
1435 CarlaActor->
GetActor()->GetComponents(Components);
1437 USceneComponent* Component =
nullptr;
1438 for(
auto Cmp : Components)
1440 if(USceneComponent* SCMP = Cast<USceneComponent>(Cmp))
1442 if(SCMP->GetName() == componentName.c_str())
1453 "get_actor_component_world_transform",
1455 " Component Name: " + FString(componentName.c_str()));
1458 FTransform ComponentRelativeTransform = Component->GetRelativeTransform();
1459 return cr::Transform(ComponentRelativeTransform);
1463 BIND_SYNC(get_actor_bone_world_transforms) << [
this](
1464 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
1471 "get_actor_bone_world_transforms",
1473 " Actor Id: " + FString::FromInt(ActorId));
1477 TArray<FTransform> BoneWorldTransforms;
1478 TArray<USkinnedMeshComponent*> SkinnedMeshComponents;
1479 CarlaActor->
GetActor()->GetComponents<USkinnedMeshComponent>(SkinnedMeshComponents);
1480 if(!SkinnedMeshComponents[0])
1483 "get_actor_bone_world_transforms",
1485 " Component Name: SkinnedMeshComponent ");
1489 for(USkinnedMeshComponent* SkinnedMeshComponent : SkinnedMeshComponents)
1491 const int32 NumBones = SkinnedMeshComponent->GetNumBones();
1492 for (int32 BoneIndex = 0; BoneIndex < NumBones; ++BoneIndex)
1494 FTransform WorldTransform = SkinnedMeshComponent->GetComponentTransform();
1495 FTransform BoneTransform = SkinnedMeshComponent->GetBoneTransform(BoneIndex, WorldTransform);
1496 BoneWorldTransforms.Add(BoneTransform);
1499 return MakeVectorFromTArray<cr::Transform>(BoneWorldTransforms);
1504 BIND_SYNC(get_actor_bone_relative_transforms) << [
this](
1505 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
1512 "get_actor_bone_relative_transforms",
1514 " Actor Id: " + FString::FromInt(ActorId));
1518 TArray<FTransform> BoneRelativeTransforms;
1519 TArray<USkinnedMeshComponent*> SkinnedMeshComponents;
1520 CarlaActor->
GetActor()->GetComponents<USkinnedMeshComponent>(SkinnedMeshComponents);
1521 if(!SkinnedMeshComponents[0])
1524 "get_actor_bone_relative_transforms",
1526 " Component Name: SkinnedMeshComponent ");
1530 for(USkinnedMeshComponent* SkinnedMeshComponent : SkinnedMeshComponents)
1532 const int32 NumBones = SkinnedMeshComponent->GetNumBones();
1533 for (int32 BoneIndex = 0; BoneIndex < NumBones; ++BoneIndex)
1535 FTransform BoneTransform = SkinnedMeshComponent->GetBoneTransform(BoneIndex, FTransform::Identity);
1536 BoneRelativeTransforms.Add(BoneTransform);
1539 return MakeVectorFromTArray<cr::Transform>(BoneRelativeTransforms);
1544 BIND_SYNC(get_actor_component_names) << [
this](
1545 cr::ActorId ActorId) ->
R<std::vector<std::string>>
1552 "get_actor_component_names",
1554 " Actor Id: " + FString::FromInt(ActorId));
1558 TArray<UActorComponent*> Components;
1559 CarlaActor->
GetActor()->GetComponents(Components);
1560 std::vector<std::string> ComponentNames;
1561 for(
auto Cmp : Components)
1563 FString ComponentName = Cmp->GetName();
1564 ComponentNames.push_back(TCHAR_TO_UTF8(*ComponentName));
1566 return ComponentNames;
1570 BIND_SYNC(get_actor_bone_names) << [
this](
1571 cr::ActorId ActorId) ->
R<std::vector<std::string>>
1578 "get_actor_bone_names",
1580 " Actor Id: " + FString::FromInt(ActorId));
1584 USkinnedMeshComponent* SkinnedMeshComponent = CarlaActor->
GetActor()->FindComponentByClass<USkinnedMeshComponent>();
1585 if(!SkinnedMeshComponent)
1588 "get_actor_bone_names",
1590 " Component Name: SkinnedMeshComponent ");
1594 TArray<FName> BoneNames;
1595 SkinnedMeshComponent->GetBoneNames(BoneNames);
1596 TArray<std::string> StringBoneNames;
1597 for (
const FName& Name : BoneNames)
1599 FString FBoneName = Name.ToString();
1600 std::string StringBoneName = TCHAR_TO_UTF8(*FBoneName);
1601 StringBoneNames.Add(StringBoneName);
1603 return MakeVectorFromTArray<std::string>(StringBoneNames);
1608 BIND_SYNC(get_actor_socket_world_transforms) << [
this](
1609 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
1616 "get_actor_socket_world_transforms",
1618 " Actor Id: " + FString::FromInt(ActorId));
1622 TArray<FTransform> SocketWorldTransforms;
1623 TArray<UActorComponent*> Components;
1624 CarlaActor->
GetActor()->GetComponents(Components);
1625 for(UActorComponent* ActorComponent : Components)
1627 if(USceneComponent* SceneComponent = Cast<USceneComponent>(ActorComponent))
1629 const TArray<FName>& SocketNames = SceneComponent->GetAllSocketNames();
1630 for (
const FName& SocketName : SocketNames)
1632 FTransform SocketTransform = SceneComponent->GetSocketTransform(SocketName);
1633 SocketWorldTransforms.Add(SocketTransform);
1637 return MakeVectorFromTArray<cr::Transform>(SocketWorldTransforms);
1641 BIND_SYNC(get_actor_socket_relative_transforms) << [
this](
1642 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
1649 "get_actor_socket_relative_transforms",
1651 " Actor Id: " + FString::FromInt(ActorId));
1655 TArray<FTransform> SocketRelativeTransforms;
1656 TArray<UActorComponent*> Components;
1657 CarlaActor->
GetActor()->GetComponents(Components);
1658 for(UActorComponent* ActorComponent : Components)
1660 if(USceneComponent* SceneComponent = Cast<USceneComponent>(ActorComponent))
1662 const TArray<FName>& SocketNames = SceneComponent->GetAllSocketNames();
1663 for (
const FName& SocketName : SocketNames)
1665 FTransform SocketTransform = SceneComponent->GetSocketTransform(SocketName, ERelativeTransformSpace::RTS_Actor);
1666 SocketRelativeTransforms.Add(SocketTransform);
1670 return MakeVectorFromTArray<cr::Transform>(SocketRelativeTransforms);
1674 BIND_SYNC(get_actor_socket_names) << [
this](
1675 cr::ActorId ActorId) ->
R<std::vector<std::string>>
1682 "get_actor_socket_names",
1684 " Actor Id: " + FString::FromInt(ActorId));
1688 TArray<FName> SocketNames;
1689 std::vector<std::string> StringSocketNames;
1690 TArray<UActorComponent*> Components;
1691 CarlaActor->
GetActor()->GetComponents(Components);
1692 for(UActorComponent* ActorComponent : Components)
1694 if(USceneComponent* SceneComponent = Cast<USceneComponent>(ActorComponent))
1696 SocketNames = SceneComponent->GetAllSocketNames();
1697 for (
const FName& Name : SocketNames)
1699 FString FSocketName = Name.ToString();
1700 std::string StringSocketName = TCHAR_TO_UTF8(*FSocketName);
1701 StringSocketNames.push_back(StringSocketName);
1705 return StringSocketNames;
1710 BIND_SYNC(get_physics_control) << [
this](
1718 "get_physics_control",
1720 " Actor Id: " + FString::FromInt(ActorId));
1728 "get_physics_control",
1730 " Actor Id: " + FString::FromInt(ActorId));
1735 BIND_SYNC(get_vehicle_light_state) << [
this](
1743 "get_vehicle_light_state",
1745 " Actor Id: " + FString::FromInt(ActorId));
1753 "get_vehicle_light_state",
1755 " Actor Id: " + FString::FromInt(ActorId));
1760 BIND_SYNC(apply_physics_control) << [
this](
1761 cr::ActorId ActorId,
1769 "apply_physics_control",
1771 " Actor Id: " + FString::FromInt(ActorId));
1778 "apply_physics_control",
1780 " Actor Id: " + FString::FromInt(ActorId));
1785 BIND_SYNC(set_vehicle_light_state) << [
this](
1786 cr::ActorId ActorId,
1794 "set_vehicle_light_state",
1796 " Actor Id: " + FString::FromInt(ActorId));
1803 "set_vehicle_light_state",
1805 " Actor Id: " + FString::FromInt(ActorId));
1812 cr::ActorId ActorId,
1813 cr::VehicleDoor DoorIdx) ->
R<void>
1820 "open_vehicle_door",
1822 " Actor Id: " + FString::FromInt(ActorId));
1829 "open_vehicle_door",
1831 " Actor Id: " + FString::FromInt(ActorId));
1836 BIND_SYNC(close_vehicle_door) << [
this](
1837 cr::ActorId ActorId,
1838 cr::VehicleDoor DoorIdx) ->
R<void>
1845 "close_vehicle_door",
1847 " Actor Id: " + FString::FromInt(ActorId));
1854 "close_vehicle_door",
1856 " Actor Id: " + FString::FromInt(ActorId));
1861 BIND_SYNC(set_wheel_steer_direction) << [
this](
1862 cr::ActorId ActorId,
1863 cr::VehicleWheelLocation WheelLocation,
1870 "set_wheel_steer_direction",
1872 " Actor Id: " + FString::FromInt(ActorId));
1880 "set_wheel_steer_direction",
1882 " Actor Id: " + FString::FromInt(ActorId));
1887 BIND_SYNC(get_wheel_steer_angle) << [
this](
1888 const cr::ActorId ActorId,
1889 cr::VehicleWheelLocation WheelLocation) ->
R<float>
1895 "get_wheel_steer_angle",
1897 " Actor Id: " + FString::FromInt(ActorId));
1906 "get_wheel_steer_angle",
1908 " Actor Id: " + FString::FromInt(ActorId));
1913 BIND_SYNC(set_actor_simulate_physics) << [
this](
1914 cr::ActorId ActorId,
1922 "set_actor_simulate_physics",
1924 " Actor Id: " + FString::FromInt(ActorId));
1931 "set_actor_simulate_physics",
1933 " Actor Id: " + FString::FromInt(ActorId));
1938 BIND_SYNC(set_actor_collisions) << [
this](
1939 cr::ActorId ActorId,
1947 "set_actor_collisions",
1949 " Actor Id: " + FString::FromInt(ActorId));
1956 "set_actor_collisions",
1958 " Actor Id: " + FString::FromInt(ActorId));
1964 cr::ActorId ActorId) ->
R<void>
1973 " Actor Id: " + FString::FromInt(ActorId));
1982 " Actor Id: " + FString::FromInt(ActorId));
1987 BIND_SYNC(set_actor_enable_gravity) << [
this](
1988 cr::ActorId ActorId,
1996 "set_actor_enable_gravity",
1998 " Actor Id: " + FString::FromInt(ActorId));
2005 "set_actor_enable_gravity",
2007 " Actor Id: " + FString::FromInt(ActorId));
2014 BIND_SYNC(apply_control_to_vehicle) << [
this](
2015 cr::ActorId ActorId,
2023 "apply_control_to_vehicle",
2025 " Actor Id: " + FString::FromInt(ActorId));
2032 "apply_control_to_vehicle",
2034 " Actor Id: " + FString::FromInt(ActorId));
2039 BIND_SYNC(apply_ackermann_control_to_vehicle) << [
this](
2040 cr::ActorId ActorId,
2048 "apply_ackermann_control_to_vehicle",
2050 " Actor Id: " + FString::FromInt(ActorId));
2057 "apply_ackermann_control_to_vehicle",
2059 " Actor Id: " + FString::FromInt(ActorId));
2064 BIND_SYNC(get_ackermann_controller_settings) << [
this](
2072 "get_ackermann_controller_settings",
2074 " Actor Id: " + FString::FromInt(ActorId));
2082 "get_ackermann_controller_settings",
2084 " Actor Id: " + FString::FromInt(ActorId));
2086 return cr::AckermannControllerSettings(Settings);
2089 BIND_SYNC(apply_ackermann_controller_settings) << [
this](
2090 cr::ActorId ActorId,
2091 cr::AckermannControllerSettings AckermannSettings) ->
R<void>
2098 "apply_ackermann_controller_settings",
2100 " Actor Id: " + FString::FromInt(ActorId));
2107 "apply_ackermann_controller_settings",
2109 " Actor Id: " + FString::FromInt(ActorId));
2114 BIND_SYNC(apply_control_to_walker) << [
this](
2115 cr::ActorId ActorId,
2123 "apply_control_to_walker",
2125 " Actor Id: " + FString::FromInt(ActorId));
2132 "apply_control_to_walker",
2134 " Actor Id: " + FString::FromInt(ActorId));
2139 BIND_SYNC(get_bones_transform) << [
this](
2147 "get_bones_transform",
2149 " Actor Id: " + FString::FromInt(ActorId));
2157 "get_bones_transform",
2159 " Actor Id: " + FString::FromInt(ActorId));
2162 std::vector<carla::rpc::BoneTransformDataOut> BoneData;
2166 Data.
bone_name = std::string(TCHAR_TO_UTF8(*Bone.Get<0>()));
2171 BoneData.push_back(Data);
2176 BIND_SYNC(set_bones_transform) << [
this](
2177 cr::ActorId ActorId,
2185 "set_bones_transform",
2187 " Actor Id: " + FString::FromInt(ActorId));
2195 "set_bones_transform",
2197 " Actor Id: " + FString::FromInt(ActorId));
2204 cr::ActorId ActorId,
2214 " Actor Id: " + FString::FromInt(ActorId));
2223 " Actor Id: " + FString::FromInt(ActorId));
2229 BIND_SYNC(get_pose_from_animation) << [
this](
2230 cr::ActorId ActorId) ->
R<void>
2237 "get_pose_from_animation",
2239 " Actor Id: " + FString::FromInt(ActorId));
2246 "get_pose_from_animation",
2248 " Actor Id: " + FString::FromInt(ActorId));
2254 BIND_SYNC(set_actor_autopilot) << [
this](
2255 cr::ActorId ActorId,
2263 "set_actor_autopilot",
2265 " Actor Id: " + FString::FromInt(ActorId));
2272 "set_actor_autopilot",
2274 " Actor Id: " + FString::FromInt(ActorId));
2279 BIND_SYNC(get_telemetry_data) << [
this](
2287 "get_telemetry_data",
2289 " Actor Id: " + FString::FromInt(ActorId));
2297 "get_telemetry_data",
2299 " Actor Id: " + FString::FromInt(ActorId));
2301 return cr::VehicleTelemetryData(TelemetryData);
2304 BIND_SYNC(show_vehicle_debug_telemetry) << [
this](
2305 cr::ActorId ActorId,
2313 "show_vehicle_debug_telemetry",
2315 " Actor Id: " + FString::FromInt(ActorId));
2322 "show_vehicle_debug_telemetry",
2324 " Actor Id: " + FString::FromInt(ActorId));
2330 cr::ActorId ActorId,
2331 std::string SimfilePath) ->
R<void>
2340 " Actor Id: " + FString::FromInt(ActorId));
2343 CarlaActor->
EnableCarSim(carla::rpc::ToFString(SimfilePath));
2349 " Actor Id: " + FString::FromInt(ActorId));
2355 cr::ActorId ActorId,
2365 " Actor Id: " + FString::FromInt(ActorId));
2374 " Actor Id: " + FString::FromInt(ActorId));
2379 BIND_SYNC(enable_chrono_physics) << [
this](
2380 cr::ActorId ActorId,
2381 uint64_t MaxSubsteps,
2382 float MaxSubstepDeltaTime,
2383 std::string VehicleJSON,
2384 std::string PowertrainJSON,
2385 std::string TireJSON,
2386 std::string BaseJSONPath) ->
R<void>
2393 "enable_chrono_physics",
2395 " Actor Id: " + FString::FromInt(ActorId));
2399 MaxSubsteps, MaxSubstepDeltaTime,
2400 cr::ToFString(VehicleJSON),
2401 cr::ToFString(PowertrainJSON),
2402 cr::ToFString(TireJSON),
2403 cr::ToFString(BaseJSONPath));
2407 "enable_chrono_physics",
2409 " Actor Id: " + FString::FromInt(ActorId));
2414 BIND_SYNC(restore_physx_physics) << [
this](
2415 cr::ActorId ActorId) ->
R<void>
2422 "restore_physx_physics",
2424 " Actor Id: " + FString::FromInt(ActorId));
2431 "restore_physx_physics",
2433 " Actor Id: " + FString::FromInt(ActorId));
2440 BIND_SYNC(set_traffic_light_state) << [
this](
2441 cr::ActorId ActorId,
2442 cr::TrafficLightState trafficLightState) ->
R<void>
2449 "set_traffic_light_state",
2451 " Actor Id: " + FString::FromInt(ActorId));
2459 "set_traffic_light_state",
2461 " Actor Id: " + FString::FromInt(ActorId));
2466 BIND_SYNC(set_traffic_light_green_time) << [
this](
2467 cr::ActorId ActorId,
2475 "set_traffic_light_green_time",
2477 " Actor Id: " + FString::FromInt(ActorId));
2484 "set_traffic_light_green_time",
2486 " Actor Id: " + FString::FromInt(ActorId));
2491 BIND_SYNC(set_traffic_light_yellow_time) << [
this](
2492 cr::ActorId ActorId,
2500 "set_traffic_light_yellow_time",
2502 " Actor Id: " + FString::FromInt(ActorId));
2509 "set_traffic_light_yellow_time",
2511 " Actor Id: " + FString::FromInt(ActorId));
2516 BIND_SYNC(set_traffic_light_red_time) << [
this](
2517 cr::ActorId ActorId,
2525 "set_traffic_light_red_time",
2527 " Actor Id: " + FString::FromInt(ActorId));
2534 "set_traffic_light_red_time",
2536 " Actor Id: " + FString::FromInt(ActorId));
2541 BIND_SYNC(freeze_traffic_light) << [
this](
2542 cr::ActorId ActorId,
2550 "freeze_traffic_light",
2552 " Actor Id: " + FString::FromInt(ActorId));
2559 "freeze_traffic_light",
2561 " Actor Id: " + FString::FromInt(ActorId));
2566 BIND_SYNC(reset_traffic_light_group) << [
this](
2567 cr::ActorId ActorId) ->
R<void>
2574 "reset_traffic_light_group",
2576 " Actor Id: " + FString::FromInt(ActorId));
2583 "reset_traffic_light_group",
2585 " Actor Id: " + FString::FromInt(ActorId));
2593 for (TActorIterator<ATrafficLightGroup> It(
Episode->GetWorld()); It; ++It)
2600 BIND_SYNC(freeze_all_traffic_lights) << [
this]
2609 auto* TraffiLightManager = GameMode->GetTrafficLightManager();
2610 TraffiLightManager->SetFrozen(frozen);
2617 cr::VehicleLightStateList List;
2619 auto It =
Episode->GetActorRegistry().begin();
2620 for (; It !=
Episode->GetActorRegistry().
end(); ++It)
2632 if (!
Actor->IsPendingKill())
2637 cr::VehicleLightState(
Vehicle->GetVehicleLightState()).GetLightStateAsValue());
2645 BIND_SYNC(get_group_traffic_lights) << [
this](
2646 const cr::ActorId ActorId) ->
R<std::vector<cr::ActorId>>
2652 RESPOND_ERROR(
"unable to get group traffic lights: actor not found");
2657 return std::vector<cr::ActorId>();
2664 RESPOND_ERROR(
"unable to get group traffic lights: actor is not a traffic light");
2666 std::vector<cr::ActorId> Result;
2667 for (
auto* TLight :
TrafficLight->GetGroupTrafficLights())
2669 auto* View =
Episode->FindCarlaActor(TLight);
2672 Result.push_back(View->GetActorId());
2680 const cr::ActorId ActorId) ->
R<std::vector<cg::BoundingBox>>
2689 " Actor Id: " + FString::FromInt(ActorId));
2696 " Actor Id: " + FString::FromInt(ActorId));
2706 " Actor Id: " + FString::FromInt(ActorId));
2708 TArray<FBoundingBox> Result;
2709 TArray<uint8> OutTag;
2713 return MakeVectorFromTArray<cg::BoundingBox>(Result);
2718 BIND_SYNC(get_gbuffer_token) << [
this](
const cr::ActorId ActorId, uint32_t GBufferId) ->
R<std::vector<unsigned char>>
2725 "get_gbuffer_token",
2727 " Actor Id: " + FString::FromInt(ActorId));
2732 "get_gbuffer_token",
2734 " Actor Id: " + FString::FromInt(ActorId));
2740 "get_gbuffer_token",
2742 " Actor Id: " + FString::FromInt(ActorId));
2750 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2755 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2760 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2765 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2770 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2775 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2780 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2785 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2790 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2795 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2800 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2805 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2810 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2813 UE_LOG(LogCarla, Error, TEXT(
"Requested invalid GBuffer ID %u"), GBufferId);
2829 Episode->GetRecorder()->Stop();
2833 BIND_SYNC(show_recorder_file_info) << [
this](
2843 BIND_SYNC(show_recorder_collisions) << [
this](
2855 BIND_SYNC(show_recorder_actors_blocked) << [
this](
2883 BIND_SYNC(set_replayer_time_factor) << [
this](
double time_factor) ->
R<void>
2886 Episode->GetRecorder()->SetReplayerTimeFactor(time_factor);
2893 Episode->GetRecorder()->SetReplayerIgnoreHero(ignore_hero);
2897 BIND_SYNC(set_replayer_ignore_spectator) << [
this](
bool ignore_spectator) ->
R<void>
2900 Episode->GetRecorder()->SetReplayerIgnoreSpectator(ignore_spectator);
2907 Episode->GetRecorder()->StopReplayer(keep_actors);
2913 BIND_SYNC(draw_debug_shape) << [
this](
const cr::DebugShape &shape) ->
R<void>
2917 check(
World !=
nullptr);
2925 using C = cr::Command;
2926 using CR = cr::CommandResponse;
2929 auto parse_result = [](ActorId id,
const auto &response) {
2930 return response.HasError() ? CR{response.GetError()} : CR{
id};
2933#define MAKE_RESULT(operation) return parse_result(c.actor, operation);
2936 [=](
auto self,
const C::SpawnActor &c) -> CR {
2937 auto result = c.parent.has_value() ?
2938 spawn_actor_with_parent(
2942 cr::AttachmentType::Rigid,
2944 spawn_actor(c.description, c.transform);
2945 if (!result.HasError())
2947 ActorId
id = result.Get().id;
2949 [](C::SpawnActor &) {},
2950 [](C::ConsoleCommand &) {},
2951 [id](
auto &s) { s.actor = id; });
2952 for (
auto command : c.do_after)
2954 boost::variant2::visit(set_id, command.command);
2955 boost::variant2::visit(self, command.command);
2959 return result.GetError();
2961 [=](
auto,
const C::DestroyActor &c) {
MAKE_RESULT(destroy_actor(c.actor)); },
2962 [=](
auto,
const C::ApplyVehicleControl &c) {
MAKE_RESULT(apply_control_to_vehicle(c.actor, c.control)); },
2963 [=](
auto,
const C::ApplyVehicleAckermannControl &c) {
MAKE_RESULT(apply_ackermann_control_to_vehicle(c.actor, c.control)); },
2964 [=](
auto,
const C::ApplyWalkerControl &c) {
MAKE_RESULT(apply_control_to_walker(c.actor, c.control)); },
2965 [=](
auto,
const C::ApplyVehiclePhysicsControl &c) {
MAKE_RESULT(apply_physics_control(c.actor, c.physics_control)); },
2966 [=](
auto,
const C::ApplyTransform &c) {
MAKE_RESULT(set_actor_transform(c.actor, c.transform)); },
2967 [=](
auto,
const C::ApplyTargetVelocity &c) {
MAKE_RESULT(set_actor_target_velocity(c.actor, c.velocity)); },
2968 [=](
auto,
const C::ApplyTargetAngularVelocity &c) {
MAKE_RESULT(set_actor_target_angular_velocity(c.actor, c.angular_velocity)); },
2969 [=](
auto,
const C::ApplyImpulse &c) {
MAKE_RESULT(add_actor_impulse(c.actor, c.impulse)); },
2970 [=](
auto,
const C::ApplyForce &c) {
MAKE_RESULT(add_actor_force(c.actor, c.force)); },
2971 [=](
auto,
const C::ApplyAngularImpulse &c) {
MAKE_RESULT(add_actor_angular_impulse(c.actor, c.impulse)); },
2972 [=](
auto,
const C::ApplyTorque &c) {
MAKE_RESULT(add_actor_torque(c.actor, c.torque)); },
2973 [=](
auto,
const C::SetSimulatePhysics &c) {
MAKE_RESULT(set_actor_simulate_physics(c.actor, c.enabled)); },
2974 [=](
auto,
const C::SetEnableGravity &c) {
MAKE_RESULT(set_actor_enable_gravity(c.actor, c.enabled)); },
2976 [=](
auto,
const C::SetAutopilot &c) {
MAKE_RESULT(set_actor_autopilot(c.actor, c.enabled)); },
2977 [=](
auto,
const C::ShowDebugTelemetry &c) {
MAKE_RESULT(show_vehicle_debug_telemetry(c.actor, c.enabled)); },
2978 [=](
auto,
const C::SetVehicleLightState &c) {
MAKE_RESULT(set_vehicle_light_state(c.actor, c.light_state)); },
2981 [=](
auto,
const C::ApplyWalkerState &c) {
MAKE_RESULT(set_walker_state(c.actor, c.transform, c.speed)); },
2982 [=](
auto,
const C::ConsoleCommand& c) -> CR {
return console_command(c.cmd); },
2983 [=](
auto,
const C::SetTrafficLightState& c) {
MAKE_RESULT(set_traffic_light_state(c.actor, c.traffic_light_state)); },
2984 [=](
auto,
const C::ApplyLocation& c) {
MAKE_RESULT(set_actor_location(c.actor, c.location)); }
2990 const std::vector<cr::Command> &commands,
2993 std::vector<CR> result;
2994 result.reserve(commands.size());
2995 for (
const auto &command : commands)
2997 result.emplace_back(boost::variant2::visit(command_visitor, command.command));
3008 BIND_SYNC(query_lights_state) << [
this](std::string
client) ->
R<std::vector<cr::LightState>>
3011 std::vector<cr::LightState> result;
3020 BIND_SYNC(update_lights_state) << [
this]
3021 (std::string
client,
const std::vector<cr::LightState>& lights,
bool discard_client) ->
R<void>
3027 CarlaLightSubsystem->
SetLights(FString(
client.c_str()), lights, discard_client);
3032 BIND_SYNC(update_day_night_cycle) << [
this]
3048 (cr::Location Location, cr::Vector3D Direction,
float SearchDistance)
3049 ->
R<std::pair<bool,cr::LabelledPoint>>
3053 constexpr float meter_to_centimeter = 100.0f;
3054 FVector UELocation = Location;
3062 meter_to_centimeter * SearchDistance,
World);
3066 (cr::Location StartLocation, cr::Location EndLocation)
3067 ->
R<std::vector<cr::LabelledPoint>>
3071 FVector UEStartLocation = StartLocation;
3072 FVector UEEndLocation = EndLocation;