CARLA
Loading...
Searching...
No Matches
CarlaEpisode.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
9#include "Carla.h"
11#include "Carla/Sensor/Sensor.h"
14
19#include "Carla/Game/Tagger.h"
22
24#include <carla/MsgPack.h>
26#include <carla/rpc/String.h>
28
29#include <util/ue-header-guard-begin.h>
30#include "Async/Async.h"
31#include "HAL/PlatformProcess.h"
32#include "Components/WorldPartitionStreamingSourceComponent.h"
33#include "WorldPartition/WorldPartition.h"
34#include "WorldPartition/WorldPartitionSubsystem.h"
35#include "Engine/StaticMeshActor.h"
36#include "EngineUtils.h"
37#include "GameFramework/SpectatorPawn.h"
38#include "GenericPlatform/GenericPlatformProcess.h"
39#include "Kismet/GameplayStatics.h"
40#include "Materials/MaterialParameterCollection.h"
41#include "Materials/MaterialParameterCollectionInstance.h"
42#include "Misc/FileHelper.h"
43#include "Misc/PackageName.h"
44#include "Misc/Paths.h"
45#include <util/ue-header-guard-end.h>
46
47constexpr TCHAR DefaultRecastBuilderPath[] = TEXT(RECASTBUILDER_PATH);
48
49static FString BuildRecastBuilderFile()
50{
51 auto Path = FPaths::RootDir();
52#if PLATFORM_WINDOWS
53 Path += TEXT("Tools/RecastBuilder.exe");
54#else
55 Path += TEXT("Tools/RecastBuilder");
56#endif
57 Path = FPaths::ConvertRelativePathToFull(Path);
58
59 if (FPaths::FileExists(Path))
60 return Path;
61 else
63}
64
65// State of the background RecastBuilder run of the last generated OpenDRIVE
66// world (there is at most one). Readers of the navmesh wait on it.
67static FCriticalSection GNavBuildLock;
68static bool GNavBuildPending = false;
69static bool GNavBuildSucceeded = false;
70
72{
73 const double Start = FPlatformTime::Seconds();
74 bool bLogged = false;
75 for (;;)
76 {
77 {
78 FScopeLock Lock(&GNavBuildLock);
80 {
81 return GNavBuildSucceeded;
82 }
83 }
84 if (!bLogged)
85 {
86 UE_LOG(LogCarla, Log, TEXT("Waiting for RecastBuilder to finish the pedestrian navigation (up to %.0f s)"),
87 TimeoutSeconds);
88 bLogged = true;
89 }
90 if (FPlatformTime::Seconds() - Start > TimeoutSeconds)
91 {
92 UE_LOG(LogCarla, Error, TEXT("RecastBuilder did not finish within %.0f s; "
93 "the pedestrian navigation of this OpenDRIVE world is not available yet"), TimeoutSeconds);
94 return false;
95 }
96 FPlatformProcess::Sleep(0.05f);
97 }
98}
99
101{
102 // Saved/ copies of the generated world outlive the process; a stale pair
103 // (or a .bin from another .xodr) must never shadow the cooked stub.
104 const FString SavedDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir());
105 for (const FString &File : {
106 SavedDir / TEXT("OpenDrive/OpenDriveMap.xodr"),
107 SavedDir / TEXT("Nav/OpenDriveMap.obj"),
108 SavedDir / TEXT("Nav/OpenDriveMap.bin")})
109 {
110 if (IFileManager::Get().FileExists(*File))
111 {
112 IFileManager::Get().Delete(*File, false, true, true);
113 UE_LOG(LogCarla, Log, TEXT("Removed stale generated-world file '%s'"), *File);
114 }
115 }
116}
117
119{
120 using TSS = ETrafficSignState;
121 const int32 Kmh = Sign.GetSpeedLimitKmh();
122 if (Kmh > 0)
123 {
124 // km/h always (the OpenDRIVE subtype vocabulary); mph plates are a look, not a unit.
125 return FString::Printf(TEXT("traffic.speed_limit.%d"), Kmh);
126 }
127 switch (Sign.GetTrafficSignState())
128 {
129 case TSS::TrafficLightRed:
130 case TSS::TrafficLightYellow:
131 case TSS::TrafficLightGreen: return TEXT("traffic.traffic_light");
132 case TSS::StopSign: return TEXT("traffic.stop");
133 case TSS::YieldSign: return TEXT("traffic.yield");
134 default: return TEXT("traffic.unknown");
135 }
136}
137
138UCarlaEpisode::UCarlaEpisode(const FObjectInitializer &ObjectInitializer)
139 : Super(ObjectInitializer),
140 Id(URandomEngine::GenerateRandomId())
141{
142 ActorDispatcher = CreateDefaultSubobject<UActorDispatcher>(TEXT("ActorDispatcher"));
143 FrameData.SetEpisode(this);
144
145 const FString AbsoluteRecastBuilderPath = BuildRecastBuilderFile();
146
147 if (!FPaths::FileExists(AbsoluteRecastBuilderPath))
148 {
149 UE_LOG(LogCarla, Warning, TEXT("'RecastBuilder' not present under '%s', "
150 "the binaries for pedestrian navigation will not be created."),
151 *AbsoluteRecastBuilderPath);
152 }
153}
154
155bool UCarlaEpisode::LoadNewEpisode(const FString &MapString, bool ResetSettings)
156{
157 FString FinalPath = UCarlaStatics::FindMapPath(MapString);
158 const bool bIsFileFound = !FinalPath.IsEmpty();
159
160 if (bIsFileFound)
161 {
162 UE_LOG(LogCarla, Warning, TEXT("Loading a new episode: %s"), *FinalPath);
163 UGameplayStatics::OpenLevel(GetWorld(), *FinalPath, true);
164 if (ResetSettings)
166
167 // send 'LOAD_MAP' command to all secondary servers (if any)
169 {
170 UCarlaGameInstance *GameInstance = UCarlaStatics::GetGameInstance(GetWorld());
171 if(GameInstance)
172 {
173 FCarlaEngine *CarlaEngine = GameInstance->GetCarlaEngine();
174 auto SecondaryServer = CarlaEngine->GetSecondaryServer();
175 // A world generated from OpenDRIVE: the secondaries generate the same.
177 TArray<uint8> OpenDrive;
178 if (FPaths::GetBaseFilename(FinalPath).Equals(TEXT("OpenDriveMap"), ESearchCase::IgnoreCase) &&
179 FFileHelper::LoadFileToArray(OpenDrive, *UOpenDrive::GetSavedXODRPath(TEXT("OpenDriveMap")), FILEREAD_Silent))
180 {
181 Extras.opendrive = std::string(reinterpret_cast<const char *>(OpenDrive.GetData()), OpenDrive.Num());
182 const carla::Buffer Parameters = carla::MsgPack::Pack(GameInstance->GetOpendriveGenerationParameters());
183 Extras.generation_parameters =
184 std::string(reinterpret_cast<const char *>(Parameters.data()), Parameters.size());
185 }
186 SecondaryServer->GetCommander().SendLoadMap(std::string(TCHAR_TO_UTF8(*FinalPath)), Extras);
187 }
188 }
189 }
190 return bIsFileFound;
191}
192
193
194
196 const FString &OpenDriveString,
198{
199 if (OpenDriveString.IsEmpty())
200 {
201 UE_LOG(LogCarla, Error, TEXT("The OpenDrive string is empty."));
202 return false;
203 }
204
205 // Build the Map from the OpenDRIVE data
206 const auto CarlaMap = carla::opendrive::OpenDriveParser::Load(
207 carla::rpc::FromLongFString(OpenDriveString));
208
209 // Check the Map is correclty generated
210 if (!CarlaMap.has_value())
211 {
212 UE_LOG(LogCarla, Error, TEXT("The OpenDrive string is invalid or not supported"));
213 return false;
214 }
215
216 // Generate the OBJ (as string)
217 const auto RoadMesh = CarlaMap->GenerateMesh(Params.vertex_distance);
218 const auto CrosswalksMesh = CarlaMap->GetAllCrosswalkMesh();
219 const auto RecastOBJ = (RoadMesh + CrosswalksMesh).GenerateOBJForRecast();
220
221 // Both files go to Saved/: in a packaged build the content dir is backed
222 // by the pak and not writable. The readers (UOpenDrive::FindPathToXODRFile,
223 // FNavigationMesh::Load) look in Saved/ first. RecastBuilder writes the
224 // .bin next to the .obj. Start from a clean slate so a .bin can never
225 // belong to a different .xodr.
228 const FString AbsoluteOBJPath = FPaths::ConvertRelativePathToFull(
229 FPaths::ProjectSavedDir() / TEXT("Nav/OpenDriveMap.obj"));
230
231 // Store the OBJ string to a file in order to that RecastBuilder can load it
232 FFileHelper::SaveStringToFile(
233 carla::rpc::ToLongFString(RecastOBJ),
234 *AbsoluteOBJPath,
235 FFileHelper::EEncodingOptions::ForceUTF8,
236 &IFileManager::Get());
237
238 const FString AbsoluteXODRPath = UOpenDrive::GetSavedXODRPath(TEXT("OpenDriveMap"));
239
240 // Copy the OpenDrive as a file in the serverside
241 FFileHelper::SaveStringToFile(
242 OpenDriveString,
243 *AbsoluteXODRPath,
244 FFileHelper::EEncodingOptions::ForceUTF8,
245 &IFileManager::Get());
246
247 if (!FPaths::FileExists(AbsoluteXODRPath))
248 {
249 UE_LOG(LogCarla, Error, TEXT("ERROR: XODR not copied!"));
250 return false;
251 }
252
253 UCarlaGameInstance * GameInstance = UCarlaStatics::GetGameInstance(GetWorld());
254 if(GameInstance)
255 {
256 GameInstance->SetOpendriveGenerationParameters(Params);
257 }
258 else
259 {
260 carla::log_warning("Missing game instance");
261 }
262
263 const FString AbsoluteRecastBuilderPath = BuildRecastBuilderFile();
264 if (FPaths::FileExists(AbsoluteRecastBuilderPath) &&
266 {
267 // RecastBuilder writes <obj stem>.bin next to the .obj and always exits
268 // 0, so the .bin is the only success signal: drop the previous one first
269 // so a failed build can never hand out last session's navmesh, then watch
270 // the process off the game thread and log the outcome loudly.
271 const FString AbsoluteBinPath = FPaths::ChangeExtension(AbsoluteOBJPath, TEXT("bin"));
272 IFileManager::Get().Delete(*AbsoluteBinPath, false, true, true);
273
274 void *PipeRead = nullptr;
275 void *PipeWrite = nullptr;
276 FPlatformProcess::CreatePipe(PipeRead, PipeWrite);
277
278 /// @todo this can take too long to finish, clients need a method
279 /// to know if the navigation is available or not.
280 FProcHandle RecastHandle = FPlatformProcess::CreateProc(
281 *AbsoluteRecastBuilderPath, *AbsoluteOBJPath,
282 true, true, true, nullptr, 0, nullptr, PipeWrite, nullptr, PipeWrite);
283 if (!RecastHandle.IsValid())
284 {
285 FPlatformProcess::ClosePipe(PipeRead, PipeWrite);
286 UE_LOG(LogCarla, Error, TEXT("RecastBuilder could not be launched ('%s' '%s'); "
287 "no pedestrian navigation for this OpenDRIVE world."),
288 *AbsoluteRecastBuilderPath, *AbsoluteOBJPath);
289 }
290 else
291 {
292 UE_LOG(LogCarla, Log, TEXT("RecastBuilder started: '%s' '%s' -> '%s'"),
293 *AbsoluteRecastBuilderPath, *AbsoluteOBJPath, *AbsoluteBinPath);
294 {
295 FScopeLock Lock(&GNavBuildLock);
296 GNavBuildPending = true;
297 GNavBuildSucceeded = false;
298 }
299 Async(EAsyncExecution::Thread,
300 [RecastHandle, PipeRead, PipeWrite, AbsoluteBinPath, AbsoluteRecastBuilderPath]() mutable
301 {
302 FString Output;
303 while (FPlatformProcess::IsProcRunning(RecastHandle))
304 {
305 Output += FPlatformProcess::ReadPipe(PipeRead);
306 FPlatformProcess::Sleep(0.1f);
307 }
308 Output += FPlatformProcess::ReadPipe(PipeRead);
309 int32 ReturnCode = -1;
310 FPlatformProcess::GetProcReturnCode(RecastHandle, &ReturnCode);
311 FPlatformProcess::CloseProc(RecastHandle);
312 FPlatformProcess::ClosePipe(PipeRead, PipeWrite);
313 Output.TrimEndInline();
314 const bool bSucceeded = ReturnCode == 0 && FPaths::FileExists(AbsoluteBinPath);
315 if (!bSucceeded)
316 {
317 UE_LOG(LogCarla, Error, TEXT("RecastBuilder failed (exit code %d, '%s' %s): no pedestrian "
318 "navigation for this OpenDRIVE world. Output:\n%s"),
319 ReturnCode, *AbsoluteBinPath,
320 FPaths::FileExists(AbsoluteBinPath) ? TEXT("written") : TEXT("missing"), *Output);
321 }
322 else
323 {
324 UE_LOG(LogCarla, Log, TEXT("RecastBuilder finished: navmesh '%s' ready. Output:\n%s"),
325 *AbsoluteBinPath, *Output);
326 }
327 FScopeLock Lock(&GNavBuildLock);
328 GNavBuildPending = false;
329 GNavBuildSucceeded = bSucceeded;
330 });
331 }
332 }
333 else
334 {
335 UE_LOG(LogCarla, Warning, TEXT("'RecastBuilder' not present under '%s', "
336 "the binaries for pedestrian navigation will not be created."),
337 *AbsoluteRecastBuilderPath);
338 }
339
340 return true;
341}
342
344{
345 EpisodeSettings = Settings;
347 {
348 UE_LOG(LogCarla, Warning, TEXT("Setting ActorActiveDistance is smaller that TileStreamingDistance, TileStreamingDistance will be increased"));
350 }
352}
353
355{
357
358 return GM->GetSpawnPointsTransforms();
359}
360
362{
363 carla::rpc::Actor Actor;
364 if (CarlaActor)
365 {
366 Actor = CarlaActor->GetActorInfo()->SerializedData;
367 auto ParentId = CarlaActor->GetParent();
368 if (ParentId)
369 {
370 Actor.parent_id = ParentId;
371 }
372 }
373 else
374 {
375 UE_LOG(LogCarla, Warning, TEXT("Trying to serialize invalid actor"));
376 }
377 return Actor;
378}
379
381{
382 carla::rpc::Actor Serialized = SerializeActor(Actor);
383 if (!bIsPrimaryServer)
384 {
386 if (const FCarlaActor *Mirror = Registry.FindCarlaActor(Serialized.id))
387 {
388 Serialized.id = Mirror->GetPrimaryActorId();
389 }
390 if (Serialized.parent_id != 0u)
391 {
392 if (const FCarlaActor *Parent = Registry.FindCarlaActor(Serialized.parent_id))
393 {
394 Serialized.parent_id = Parent->GetPrimaryActorId();
395 }
396 }
397 }
398 return Serialized;
399}
400
402{
403#if defined(WITH_ROS2)
404 auto ROS2 = carla::ros2::ROS2::GetInstance();
405 if (!ROS2->IsEnabled())
406 {
407 return;
408 }
409 FCarlaActor *CurrentActor = FindCarlaActor(Child.GetParent());
410 while (CurrentActor)
411 {
412 for (const auto &Attr : CurrentActor->GetActorInfo()->Description.Variations)
413 {
414 if (Attr.Key == "ros_name")
415 {
416 ROS2->AddActorParentRosName(static_cast<void*>(Child.GetActor()), static_cast<void*>(CurrentActor->GetActor()));
417 }
418 // NOTE: tier4 also propagated each ancestor's ros_topic_name onto the
419 // child here, but their AddActorRosTopicName used map::insert, so the
420 // dispatcher's earlier per-actor registration (own override or "")
421 // always won and the call was a no-op. Our AddActorRosTopicName is
422 // insert_or_assign (re-registration idempotency), which made the
423 // propagation live and clobbered every attached sensor's own
424 // ros_topic_name with its ancestor's — so it is dropped entirely.
425 }
426 CurrentActor = FindCarlaActor(CurrentActor->GetParent());
427 }
428#endif
429}
430
432{
433 FCarlaActor* CarlaActor = FindCarlaActor(Actor);
434 if (CarlaActor)
435 {
436 return SerializeActor(CarlaActor);
437 }
438 else
439 {
440 carla::rpc::Actor SerializedActor;
441 SerializedActor.id = 0u;
443 TSet<crp::CityObjectLabel> SemanticTags;
444 ATagger::GetTagsOfTaggedActor(*Actor, SemanticTags);
445 FActorDescription Description;
446 Description.Id = TEXT("static.") + CarlaGetRelevantTagAsString(SemanticTags);
447 SerializedActor.description = Description;
448 SerializedActor.semantic_tags.reserve(SemanticTags.Num());
449 for (auto &&Tag : SemanticTags)
450 {
451 using tag_t = decltype(SerializedActor.semantic_tags)::value_type;
452 SerializedActor.semantic_tags.emplace_back(static_cast<tag_t>(Tag));
453 }
454 return SerializedActor;
455 }
456}
457
459 AActor *Child,
460 AActor *Parent,
461 EAttachmentType InAttachmentType)
462{
463 Child->AddActorWorldOffset(FVector(CurrentMapOrigin));
464
465 UActorAttacher::AttachActors(Child, Parent, InAttachmentType);
466
468 {
471 FindCarlaActor(Child)->GetActorId(),
472 FindCarlaActor(Parent)->GetActorId()});
473 }
474 // recorder event
475 if (Recorder->IsEnabled())
476 {
478 {
479 FindCarlaActor(Child)->GetActorId(),
480 FindCarlaActor(Parent)->GetActorId()
481 };
482 Recorder->AddEvent(std::move(RecEvent));
483 }
484}
485
487{
488 auto World = GetWorld();
489 check(World != nullptr);
490 auto PlayerController = UGameplayStatics::GetPlayerController(World, 0);
491 if (PlayerController == nullptr)
492 {
493 UE_LOG(LogCarla, Error, TEXT("Can't find player controller!"));
494 return;
495 }
496 Spectator = PlayerController->GetPawn();
497 if (Spectator != nullptr)
498 {
499 FActorDescription Description;
500 Description.Id = TEXT("spectator");
501 Description.Class = Spectator->GetClass();
503 }
504 else
505 {
506 UE_LOG(LogCarla, Error, TEXT("Can't find spectator!"));
507 }
508
509 // material parameters collection
510 UMaterialParameterCollection *Collection = LoadObject<UMaterialParameterCollection>(nullptr, TEXT("/Game/Carla/Blueprints/Game/CarlaParameters.CarlaParameters"), nullptr, LOAD_None, nullptr);
511 if (Collection != nullptr)
512 {
513 MaterialParameters = World->GetParameterCollectionInstance(Collection);
514 if (MaterialParameters == nullptr)
515 {
516 UE_LOG(LogCarla, Error, TEXT("Can't find CarlaParameters instance!"));
517 }
518 }
519 else
520 {
521 UE_LOG(LogCarla, Error, TEXT("Can't find CarlaParameters asset!"));
522 }
523
524 for (TActorIterator<ATrafficSignBase> It(World); It; ++It)
525 {
526 ATrafficSignBase *Actor = *It;
527 check(Actor != nullptr);
528 FActorDescription Description;
529 Description.Id = UCarlaEpisode_GetTrafficSignId(*Actor);
530 Description.Class = Actor->GetClass();
531 ActorDispatcher->RegisterActor(*Actor, Description);
532 }
533
534 // get the definition id for static.prop.mesh
535 auto Definitions = GetActorDefinitions();
536 uint32 StaticMeshUId = 0;
537 for (auto& Definition : Definitions)
538 {
539 if (Definition.Id == "static.prop.mesh")
540 {
541 StaticMeshUId = Definition.UId;
542 break;
543 }
544 }
545
546 for (TActorIterator<AStaticMeshActor> It(World); It; ++It)
547 {
548 auto Actor = *It;
549 check(Actor != nullptr);
550 auto MeshComponent = Actor->GetStaticMeshComponent();
551 check(MeshComponent != nullptr);
552 if (MeshComponent->Mobility == EComponentMobility::Movable)
553 {
554 FActorDescription Description;
555 Description.Id = TEXT("static.prop.mesh");
556 Description.UId = StaticMeshUId;
557 Description.Class = Actor->GetClass();
558 Description.Variations.Add("mesh_path",
560 MeshComponent->GetStaticMesh()->GetPathName()});
561 Description.Variations.Add("mass",
563 FString::SanitizeFloat(MeshComponent->GetMass())});
564 ActorDispatcher->RegisterActor(*Actor, Description);
565 }
566 }
567}
568
570{
571 // stop recorder and replayer
572 if (Recorder)
573 {
574 Recorder->Stop();
576 {
578 }
579 }
580}
581
582std::string UCarlaEpisode::StartRecorder(std::string Name, bool AdditionalData, bool StopReplayer)
583{
584 std::string result;
585
586 if (Recorder)
587 {
588 result = Recorder->Start(Name, MapName, AdditionalData, StopReplayer);
589 }
590 else
591 {
592 result = "Recorder is not ready";
593 }
594
595 return result;
596}
597
598TPair<EActorSpawnResultStatus, FCarlaActor*> UCarlaEpisode::SpawnActorWithInfo(
599 const FTransform &Transform,
600 FActorDescription thisActorDescription,
601 FCarlaActor::IdType DesiredId)
602{
604 FTransform LocalTransform = Transform;
605 if(LargeMap)
606 {
607 LocalTransform = LargeMap->GlobalToLocalTransform(LocalTransform);
608 }
609
610 // NewTransform.AddToTranslation(-1.0f * FVector(CurrentMapOrigin));
611 auto result = ActorDispatcher->SpawnActor(LocalTransform, thisActorDescription, DesiredId);
612 if (result.Key == EActorSpawnResultStatus::Success &&
613 GetWorld()->GetWorldPartition() != nullptr)
614 {
615 // World Partition map: every physics actor needs the ground under it
616 // resident, mirroring the tile streaming the legacy LargeMapManager
617 // provided on tiled maps. The engine only streams cells around registered
618 // streaming sources; without one, a vehicle spawned away from the
619 // spectator free-falls through the unloaded road.
620 AActor* Actor = result.Value->GetActor();
621 const bool bNeedsGround =
622 Cast<ACarlaWheeledVehicle>(Actor) != nullptr ||
623 Cast<AWalkerBase>(Actor) != nullptr;
624 if (bNeedsGround &&
625 !Actor->FindComponentByClass<UWorldPartitionStreamingSourceComponent>())
626 {
627 // The hero keeps a wide loading ring like the legacy tiled maps gave
628 // it; background traffic only needs the ground in its vicinity.
629 const FActorAttribute* Attribute =
630 thisActorDescription.Variations.Find("role_name");
631 const bool bIsHero = Attribute && (Attribute->Value.Contains("hero") ||
632 Attribute->Value.Contains("ego_vehicle"));
633 auto* Source = NewObject<UWorldPartitionStreamingSourceComponent>(Actor);
634 FStreamingSourceShape Shape;
635 Shape.bUseGridLoadingRange = false;
636 Shape.Radius = bIsHero ? EpisodeSettings.TileStreamingDistance : 20000.0f;
637 Source->Shapes.Add(Shape);
638 Source->RegisterComponent();
639
640 // Physics drops the actor immediately, but cells only stream during the
641 // world partition subsystem update; run one update now and block until
642 // the requested cells are resident so the actor never outruns its
643 // ground.
644 UWorldPartitionSubsystem* WPSubsystem =
645 GetWorld()->GetSubsystem<UWorldPartitionSubsystem>();
646 if (WPSubsystem != nullptr && !WPSubsystem->IsStreamingCompleted(Source))
647 {
648 WPSubsystem->OnUpdateStreamingState();
649 GetWorld()->BlockTillLevelStreamingCompleted();
650 }
651 UE_LOG(LogCarla, Log, TEXT(
652 "WP streaming source on %s (role %s, radius %.0f cm): completed=%d"),
653 *Actor->GetName(), Attribute ? *Attribute->Value : TEXT("none"), Shape.Radius,
654 WPSubsystem ? WPSubsystem->IsStreamingCompleted(Source) : -1);
655 }
656 }
657 if (result.Key == EActorSpawnResultStatus::Success && bIsPrimaryServer)
658 {
659 if (Recorder->IsEnabled())
660 {
662 result.Value->GetActorId(),
663 static_cast<uint8_t>(result.Value->GetActorType()),
664 Transform,
665 thisActorDescription
666 );
667 }
669 {
671 result.Value->GetActorId(),
672 static_cast<uint8_t>(result.Value->GetActorType()),
673 Transform,
674 std::move(thisActorDescription));
675 }
676 }
677
678 return result;
679}
EAttachmentType
static bool GNavBuildSucceeded
static FCriticalSection GNavBuildLock
static FString BuildRecastBuilderFile()
static FString UCarlaEpisode_GetTrafficSignId(const ATrafficSignBase &Sign)
constexpr TCHAR DefaultRecastBuilderPath[]
static bool GNavBuildPending
FString CarlaGetRelevantTagAsString(const TSet< carla::rpc::CityObjectLabel > &SemanticTags)
ETrafficSignState
Base class for the CARLA Game Mode.
const TArray< FTransform > & GetSpawnPointsTransforms() const
bool IsEnabled(void)
void AddEvent(const CarlaRecorderEventAdd &Event)
CarlaReplayer * GetReplayer(void)
std::string Start(std::string Name, FString MapName, bool AdditionalData=false, bool StopReplayer=true)
void CreateRecorderEventAdd(uint32_t DatabaseId, uint8_t Type, const FTransform &Transform, FActorDescription ActorDescription)
FTransform GlobalToLocalTransform(const FTransform &InTransform) const
static void GetTagsOfTaggedActor(const AActor &Actor, TSet< crp::CityObjectLabel > &Tags)
Retrieve the tags of an already tagged actor.
Definition Tagger.cpp:221
ETrafficSignState GetTrafficSignState() const
int32 GetSpeedLimitKmh() const
km/h this sign limits to, -1 when it is not a speed-limit sign.
bool IsEnabled(void)
void Stop(bool KeepActors=false)
A registry of all the Carla actors.
FCarlaActor * FindCarlaActor(IdType Id)
A view over an actor and its properties.
Definition CarlaActor.h:25
IdType GetParent() const
Definition CarlaActor.h:121
AActor * GetActor()
Definition CarlaActor.h:91
uint32 IdType
Definition CarlaActor.h:28
const FActorInfo * GetActorInfo() const
Definition CarlaActor.h:101
IdType GetActorId() const
Definition CarlaActor.h:81
std::shared_ptr< carla::multigpu::Router > GetSecondaryServer()
Definition CarlaEngine.h:99
static FOnEpisodeSettingsChange OnEpisodeSettingsChange
void SetEpisode(UCarlaEpisode *ThisEpisode)
Definition FrameData.h:163
void AddEvent(const CarlaRecorderEventAdd &Event)
void CreateRecorderEventAdd(uint32_t DatabaseId, uint8_t Type, const FTransform &Transform, FActorDescription ActorDescription, bool bAddOtherRelatedInfo=true)
static void AttachActors(AActor *Child, AActor *Parent, EAttachmentType AttachmentType)
const FActorRegistry & GetActorRegistry() const
FCarlaActor * RegisterActor(AActor &Actor, FActorDescription ActorDescription, FActorRegistry::IdType DesiredId=0)
Register an actor that was not created using "SpawnActor" function but that should be kept in the reg...
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActor(const FTransform &Transform, FActorDescription ActorDescription, FCarlaActor::IdType DesiredId=0)
Spawns an actor based on ActorDescription at Transform.
static FBoundingBox GetActorBoundingBox(const AActor *Actor, uint8 InTagQueried=0xFF)
Compute the bounding box of the given Carla actor.
FFrameData & GetFrameData()
carla::rpc::Actor SerializeActor(FCarlaActor *CarlaActor) const
Create a serializable object describing the actor.
FEpisodeSettings EpisodeSettings
static void ClearGeneratedWorldFiles()
Delete Saved/OpenDrive|Nav/OpenDriveMap.
UCarlaEpisode(const FObjectInitializer &ObjectInitializer)
FIntVector CurrentMapOrigin
bool LoadNewOpendriveEpisode(const FString &OpenDriveString, const carla::rpc::OpendriveGenerationParameters &Params)
Load a new map generating the mesh from OpenDRIVE data and start a new episode.
const TArray< FActorDefinition > & GetActorDefinitions() const
Return the list of actor definitions that are available to be spawned this episode.
FCarlaActor * FindCarlaActor(FCarlaActor::IdType ActorId)
Find a Carla actor by id.
UActorDispatcher * ActorDispatcher
std::string StartRecorder(std::string name, bool AdditionalData, bool StopReplayer)
carla::rpc::Actor SerializeActorWithPrimaryIds(AActor *Actor) const
SerializeActor, with the ids the primary's clients know on a Multi-GPU secondary (for data a sensor s...
void ApplySettings(const FEpisodeSettings &Settings)
static bool WaitForPendingNavigationBuild(double TimeoutSeconds)
Return the name of the map loaded in this episode.
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActorWithInfo(const FTransform &Transform, FActorDescription thisActorDescription, FCarlaActor::IdType DesiredId=0)
Spawns an actor based on ActorDescription at Transform.
UMaterialParameterCollectionInstance * MaterialParameters
APawn * Spectator
ACarlaRecorder * Recorder
void InitializeAtBeginPlay()
void AddRosParentNames(FCarlaActor &Child)
ROS 2: registers the ros_name of each of Child's ancestors as one of its parent frames.
FFrameData FrameData
bool LoadNewEpisode(const FString &MapString, bool ResetSettings=true)
Load a new map and start a new episode.
void AttachActors(AActor *Child, AActor *Parent, EAttachmentType InAttachmentType=EAttachmentType::Rigid)
Attach Child to Parent.
TArray< FTransform > GetRecommendedSpawnPoints() const
Return the list of recommended spawn points for vehicles.
The game instance contains elements that must be kept alive in between levels.
const carla::rpc::OpendriveGenerationParameters & GetOpendriveGenerationParameters() const
FCarlaEngine * GetCarlaEngine()
void SetOpendriveGenerationParameters(const carla::rpc::OpendriveGenerationParameters &Parameters)
static FString FindMapPath(const FString &MapName)
static UCarlaGameInstance * GetGameInstance(const UObject *WorldContextObject)
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
static FString GetSavedXODRPath(const FString &MapName)
Where a generated OpenDRIVE world stores its xodr: <ProjectSavedDir>/OpenDrive/<MapName>....
A piece of raw data.
const value_type * data() const noexcept
Direct access to the allocated memory or nullptr if no memory is allocated.
size_type size() const noexcept
static Buffer Pack(const T &obj)
Definition MsgPack.h:19
static std::optional< road::Map > Load(const std::string &opendrive)
static std::shared_ptr< ROS2 > GetInstance()
Definition ROS2.h:61
std::vector< uint8_t > semantic_tags
Definition rpc/Actor.h:33
ActorId parent_id
Definition rpc/Actor.h:27
ActorDescription description
Definition rpc/Actor.h:29
geom::BoundingBox bounding_box
Definition rpc/Actor.h:31
static void log_warning(Args &&... args)
Definition Logging.h:96
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
A description of a Carla Actor with all its variation.
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
TSubclassOf< AActor > Class
Class of the actor to be spawned.
uint32 UId
UId of the definition in which this description was based.
FActorDescription Description
Definition ActorInfo.h:21
carla::rpc::Actor SerializedData
Definition ActorInfo.h:27
What a LOAD_MAP carries besides the map: for a world the primary generated from OpenDRIVE (generate_o...
Definition commands.h:51
std::optional< std::string > generation_parameters
Definition commands.h:53
std::optional< std::string > opendrive
Definition commands.h:52
Seting for map generation from opendrive without additional geometry.