CARLA
CarlaGameModeBase.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 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 
7 #include "Carla.h"
9 #include "Carla/Game/CarlaHUD.h"
11 #include "Engine/DecalActor.h"
12 #include "Engine/LevelStreaming.h"
13 #include "Engine/LocalPlayer.h"
14 #include "Materials/MaterialInstanceDynamic.h"
15 
21 #include <carla/rpc/MapLayer.h>
23 
24 #include "Async/ParallelFor.h"
25 #include "DynamicRHI.h"
26 
27 #include "DrawDebugHelpers.h"
28 #include "Kismet/KismetSystemLibrary.h"
29 
30 namespace cr = carla::road;
31 namespace crp = carla::rpc;
32 namespace cre = carla::road::element;
33 
34 ACarlaGameModeBase::ACarlaGameModeBase(const FObjectInitializer& ObjectInitializer)
35  : Super(ObjectInitializer)
36 {
37  PrimaryActorTick.bCanEverTick = true;
38  PrimaryActorTick.TickGroup = TG_PrePhysics;
39  bAllowTickBeforeBeginPlay = false;
40 
41  Episode = CreateDefaultSubobject<UCarlaEpisode>(TEXT("Episode"));
42 
43  Recorder = CreateDefaultSubobject<ACarlaRecorder>(TEXT("Recorder"));
44 
45  ObjectRegister = CreateDefaultSubobject<UObjectRegister>(TEXT("ObjectRegister"));
46 
47  // HUD
48  HUDClass = ACarlaHUD::StaticClass();
49 
50  TaggerDelegate = CreateDefaultSubobject<UTaggerDelegate>(TEXT("TaggerDelegate"));
51  CarlaSettingsDelegate = CreateDefaultSubobject<UCarlaSettingsDelegate>(TEXT("CarlaSettingsDelegate"));
52 }
53 
55 {
56  UWorld* World = GetWorld();
57  TSoftObjectPtr<UWorld> AssetPtr (World);
58  FString Path = FPaths::GetPath(AssetPtr.GetLongPackageName());
59  Path.RemoveFromStart("/Game/");
60  return Path;
61 }
62 
64 {
65  FString Path = GetRelativeMapPath();
66  return FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()) + Path;
67 }
68 
70  const FString &MapName,
71  const FString &Options,
72  FString &ErrorMessage)
73 {
74  TRACE_CPUPROFILER_EVENT_SCOPE(ACarlaGameModeBase::InitGame);
75  Super::InitGame(MapName, Options, ErrorMessage);
76 
77  UWorld* World = GetWorld();
78  check(World != nullptr);
79  FString InMapName(MapName);
80 
81  checkf(
82  Episode != nullptr,
83  TEXT("Missing episode, can't continue without an episode!"));
84 
85  AActor* LMManagerActor =
86  UGameplayStatics::GetActorOfClass(GetWorld(), ALargeMapManager::StaticClass());
87  LMManager = Cast<ALargeMapManager>(LMManagerActor);
88  if (LMManager) {
89  if (LMManager->GetNumTiles() == 0)
90  {
92  }
93  InMapName = LMManager->LargeMapName;
94  }
95 
96 #if WITH_EDITOR
97  {
98  // When playing in editor the map name gets an extra prefix, here we
99  // remove it.
100  FString CorrectedMapName = InMapName;
101  constexpr auto PIEPrefix = TEXT("UEDPIE_0_");
102  CorrectedMapName.RemoveFromStart(PIEPrefix);
103  UE_LOG(LogCarla, Log, TEXT("Corrected map name from %s to %s"), *InMapName, *CorrectedMapName);
104  Episode->MapName = CorrectedMapName;
105  }
106 #else
107  Episode->MapName = InMapName;
108 #endif // WITH_EDITOR
109 
110  GameInstance = Cast<UCarlaGameInstance>(GetGameInstance());
111  checkf(
112  GameInstance != nullptr,
113  TEXT("GameInstance is not a UCarlaGameInstance, did you forget to set "
114  "it in the project settings?"));
115 
116  if (TaggerDelegate != nullptr) {
118  } else {
119  UE_LOG(LogCarla, Error, TEXT("Missing TaggerDelegate!"));
120  }
121 
122  if(CarlaSettingsDelegate != nullptr) {
125  } else {
126  UE_LOG(LogCarla, Error, TEXT("Missing CarlaSettingsDelegate!"));
127  }
128 
129  if (WeatherClass != nullptr) {
130  Episode->Weather = World->SpawnActor<AWeather>(WeatherClass);
131  } else {
132  UE_LOG(LogCarla, Error, TEXT("Missing weather class!"));
133  }
134 
136 
138  this,
140 
142 
143  // make connection between Episode and Recorder
146 
147  ParseOpenDrive();
148 
149  if(Map.has_value())
150  {
152  }
153 }
154 
156 {
157  if (CarlaSettingsDelegate != nullptr)
158  {
160  }
161 
162  Super::RestartPlayer(NewPlayer);
163 }
164 
166 {
167  Super::BeginPlay();
168 
169  UWorld* World = GetWorld();
170  check(World != nullptr);
171 
173  ReadyToRegisterObjects = true;
174 
175  if (true) { /// @todo If semantic segmentation enabled.
176  ATagger::TagActorsInLevel(*World, true);
178  }
179 
180  // HACK: fix transparency see-through issues
181  // The problem: transparent objects are visible through walls.
182  // This is due to a weird interaction between the SkyAtmosphere component,
183  // the shadows of a directional light (the sun)
184  // and the custom depth set to 3 used for semantic segmentation
185  // The solution: Spawn a Decal.
186  // It just works!
187  World->SpawnActor<ADecalActor>(
188  FVector(0,0,-1000000), FRotator(0,0,0), FActorSpawnParameters());
189 
191  Manager->InitializeTrafficLights();
192 
195 
196  if (Episode->Weather != nullptr)
197  {
199  }
200 
201  /// @todo Recorder should not tick here, FCarlaEngine should do it.
202  // check if replayer is waiting to autostart
203  if (Recorder)
204  {
206  }
207 
208  if(ReadyToRegisterObjects && PendingLevelsToLoad == 0)
209  {
211  }
212 
213  if (LMManager) {
215  }
216 
217  // Manually run begin play on lights as it may not run on sublevels
218  TArray<AActor*> FoundActors;
219  UGameplayStatics::GetAllActorsOfClass(World, AActor::StaticClass(), FoundActors);
220  for(AActor* Actor : FoundActors)
221  {
222  TArray<UCarlaLight*> Lights;
223  Actor->GetComponents(Lights, false);
224  for(UCarlaLight* Light : Lights)
225  {
226  Light->RegisterLight();
227  if(!Light->HasBegunPlay())
228  {
229  Light->BeginPlay();
230  }
231  }
232  }
234 }
235 
237 {
238  TArray<FString> Names;
239  TArray<AActor*> Actors;
240  UGameplayStatics::GetAllActorsOfClass(GetWorld(), AActor::StaticClass(), Actors);
241  for (AActor* Actor : Actors)
242  {
243  TArray<UStaticMeshComponent*> StaticMeshes;
244  Actor->GetComponents(StaticMeshes);
245  if (StaticMeshes.Num())
246  {
247  Names.Add(Actor->GetName());
248  }
249  }
250  return Names;
251 }
252 
253 AActor* ACarlaGameModeBase::FindActorByName(const FString& ActorName)
254 {
255  TArray<AActor*> Actors;
256  UGameplayStatics::GetAllActorsOfClass(GetWorld(), AActor::StaticClass(), Actors);
257  for (AActor* Actor : Actors)
258  {
259  if(Actor->GetName() == ActorName)
260  {
261  return Actor;
262  break;
263  }
264  }
265  return nullptr;
266 }
267 
269 {
270  FlushRenderingCommands();
271  TArray<FColor> Colors;
272  for (uint32_t y = 0; y < Texture.GetHeight(); y++)
273  {
274  for (uint32_t x = 0; x < Texture.GetWidth(); x++)
275  {
276  auto& Color = Texture.At(x,y);
277  Colors.Add(FColor(Color.r, Color.g, Color.b, Color.a));
278  }
279  }
280  UTexture2D* UETexture = UTexture2D::CreateTransient(Texture.GetWidth(), Texture.GetHeight(), EPixelFormat::PF_B8G8R8A8);
281  FTexture2DMipMap& Mip = UETexture->PlatformData->Mips[0];
282  void* Data = Mip.BulkData.Lock( LOCK_READ_WRITE );
283  FMemory::Memcpy( Data,
284  &Colors[0],
285  Texture.GetWidth()*Texture.GetHeight()*sizeof(FColor));
286  Mip.BulkData.Unlock();
287  UETexture->UpdateResource();
288  return UETexture;
289 }
290 
292 {
293  FlushRenderingCommands();
294  TArray<FFloat16Color> Colors;
295  for (uint32_t y = 0; y < Texture.GetHeight(); y++)
296  {
297  for (uint32_t x = 0; x < Texture.GetWidth(); x++)
298  {
299  auto& Color = Texture.At(x,y);
300  Colors.Add(FLinearColor(Color.r, Color.g, Color.b, Color.a));
301  }
302  }
303  UTexture2D* UETexture = UTexture2D::CreateTransient(Texture.GetWidth(), Texture.GetHeight(), EPixelFormat::PF_FloatRGBA);
304  FTexture2DMipMap& Mip = UETexture->PlatformData->Mips[0];
305  void* Data = Mip.BulkData.Lock( LOCK_READ_WRITE );
306  FMemory::Memcpy( Data,
307  &Colors[0],
308  Texture.GetWidth()*Texture.GetHeight()*sizeof(FFloat16Color));
309  Mip.BulkData.Unlock();
310  UETexture->UpdateResource();
311  return UETexture;
312 }
313 
315  AActor* Actor,
316  UTexture2D* Texture,
317  const carla::rpc::MaterialParameter& TextureParam)
318 {
319  namespace cr = carla::rpc;
320  TArray<UStaticMeshComponent*> StaticMeshes;
321  Actor->GetComponents(StaticMeshes);
322  for (UStaticMeshComponent* Mesh : StaticMeshes)
323  {
324  for (int i = 0; i < Mesh->GetNumMaterials(); ++i)
325  {
326  UMaterialInterface* OriginalMaterial = Mesh->GetMaterial(i);
327  UMaterialInstanceDynamic* DynamicMaterial = Cast<UMaterialInstanceDynamic>(OriginalMaterial);
328  if(!DynamicMaterial)
329  {
330  DynamicMaterial = UMaterialInstanceDynamic::Create(OriginalMaterial, NULL);
331  Mesh->SetMaterial(i, DynamicMaterial);
332  }
333 
334  switch(TextureParam)
335  {
336  case cr::MaterialParameter::Tex_Diffuse:
337  DynamicMaterial->SetTextureParameterValue("BaseColor", Texture);
338  DynamicMaterial->SetTextureParameterValue("Difuse", Texture);
339  DynamicMaterial->SetTextureParameterValue("Difuse 2", Texture);
340  DynamicMaterial->SetTextureParameterValue("Difuse 3", Texture);
341  DynamicMaterial->SetTextureParameterValue("Difuse 4", Texture);
342  break;
343  case cr::MaterialParameter::Tex_Normal:
344  DynamicMaterial->SetTextureParameterValue("Normal", Texture);
345  DynamicMaterial->SetTextureParameterValue("Normal 2", Texture);
346  DynamicMaterial->SetTextureParameterValue("Normal 3", Texture);
347  DynamicMaterial->SetTextureParameterValue("Normal 4", Texture);
348  break;
349  case cr::MaterialParameter::Tex_Emissive:
350  DynamicMaterial->SetTextureParameterValue("Emissive", Texture);
351  break;
352  case cr::MaterialParameter::Tex_Ao_Roughness_Metallic_Emissive:
353  DynamicMaterial->SetTextureParameterValue("AO / Roughness / Metallic / Emissive", Texture);
354  DynamicMaterial->SetTextureParameterValue("ORMH", Texture);
355  DynamicMaterial->SetTextureParameterValue("ORMH 2", Texture);
356  DynamicMaterial->SetTextureParameterValue("ORMH 3", Texture);
357  DynamicMaterial->SetTextureParameterValue("ORMH 4", Texture);
358  break;
359  }
360  }
361  }
362 }
363 
364 void ACarlaGameModeBase::Tick(float DeltaSeconds)
365 {
366  Super::Tick(DeltaSeconds);
367 
368  /// @todo Recorder should not tick here, FCarlaEngine should do it.
369  if (Recorder)
370  {
371  Recorder->Tick(DeltaSeconds);
372  }
373 }
374 
375 void ACarlaGameModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason)
376 {
378 
379  Episode->EndPlay();
381 
382  Super::EndPlay(EndPlayReason);
383 
384  if ((CarlaSettingsDelegate != nullptr) && (EndPlayReason != EEndPlayReason::EndPlayInEditor))
385  {
387  }
388 }
389 
391 {
392  auto *World = GetWorld();
393  check(World != nullptr);
394 
395  for (auto &FactoryClass : ActorFactories)
396  {
397  if (FactoryClass != nullptr)
398  {
399  auto *Factory = World->SpawnActor<ACarlaActorFactory>(FactoryClass);
400  if (Factory != nullptr)
401  {
402  Episode->RegisterActorFactory(*Factory);
403  ActorFactoryInstances.Add(Factory);
404  }
405  else
406  {
407  UE_LOG(LogCarla, Error, TEXT("Failed to spawn actor spawner"));
408  }
409  }
410  }
411 }
412 
414 {
415  for (TActorIterator<AVehicleSpawnPoint> It(GetWorld()); It; ++It)
416  {
417  SpawnPointsTransforms.Add(It->GetActorTransform());
418  }
419 
420  if(SpawnPointsTransforms.Num() == 0)
421  {
423  }
424 
425  UE_LOG(LogCarla, Log, TEXT("There are %d SpawnPoints in the map"), SpawnPointsTransforms.Num());
426 }
427 
429 {
430  UE_LOG(LogCarla, Log, TEXT("Generating SpawnPoints ..."));
431  std::vector<std::pair<carla::road::element::Waypoint, carla::road::element::Waypoint>> Topology = Map->GenerateTopology();
432  UWorld* World = GetWorld();
433  for(auto& Pair : Topology)
434  {
435  carla::geom::Transform CarlaTransform = Map->ComputeTransform(Pair.first);
436  FTransform Transform(CarlaTransform);
437  Transform.AddToTranslation(FVector(0.f, 0.f, 300.0f));
438  SpawnPointsTransforms.Add(Transform);
439  }
440 }
441 
443 {
444  std::string opendrive_xml = carla::rpc::FromLongFString(UOpenDrive::GetXODR(GetWorld()));
446  if (!Map.has_value()) {
447  UE_LOG(LogCarla, Error, TEXT("Invalid Map"));
448  }
449  else
450  {
451  Episode->MapGeoReference = Map->GetGeoReference();
452  }
453 }
454 
456 {
457  if (!TrafficLightManager)
458  {
459  UWorld* World = GetWorld();
460  AActor* TrafficLightManagerActor = UGameplayStatics::GetActorOfClass(World, ATrafficLightManager::StaticClass());
461  if(TrafficLightManagerActor == nullptr)
462  {
463  FActorSpawnParameters SpawnParams;
464  SpawnParams.OverrideLevel = GetULevelFromName("TrafficLights");
465  TrafficLightManager = World->SpawnActor<ATrafficLightManager>(SpawnParams);
466  }
467  else
468  {
469  TrafficLightManager = Cast<ATrafficLightManager>(TrafficLightManagerActor);
470  }
471  }
472  return TrafficLightManager;
473 }
474 
476 {
477  TArray<AActor*> WorldActors;
478  UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), WorldActors);
479 
480  for (AActor *Actor : WorldActors)
481  {
482  AStaticMeshActor *MeshActor = CastChecked<AStaticMeshActor>(Actor);
483  if (MeshActor->GetStaticMeshComponent()->GetStaticMesh() == NULL)
484  {
485  UE_LOG(LogTemp, Error, TEXT("The object : %s has no mesh"), *MeshActor->GetFullName());
486  }
487  }
488 }
489 
491 {
492  TArray<AActor*> WorldActors;
493  UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), WorldActors);
494 
495  for(AActor *Actor : WorldActors)
496  {
497  AStaticMeshActor *MeshActor = CastChecked<AStaticMeshActor>(Actor);
498  if(MeshActor->GetStaticMeshComponent()->GetStaticMesh() != NULL)
499  {
500  if (MeshActor->GetStaticMeshComponent()->GetGenerateOverlapEvents() == false)
501  {
502  MeshActor->GetStaticMeshComponent()->SetGenerateOverlapEvents(true);
503  }
504  }
505  }
506 }
507 
509 {
510 
511  auto World = GetWorld();
512  check(World != nullptr);
513 
514  if(!Map)
515  {
516  return;
517  }
518 
519  if(!enable)
520  {
521  UKismetSystemLibrary::FlushDebugStrings(World);
522  UKismetSystemLibrary::FlushPersistentDebugLines(World);
523  return;
524  }
525 
526  //const std::unordered_map<carla::road::SignId, std::unique_ptr<carla::road::Signal>>
527  const auto& Signals = Map->GetSignals();
528  const auto& Controllers = Map->GetControllers();
529 
530  for(const auto& Signal : Signals) {
531  const auto& ODSignal = Signal.second;
532  const FTransform Transform = ODSignal->GetTransform();
533  const FVector Location = Transform.GetLocation();
534  const FQuat Rotation = Transform.GetRotation();
535  const FVector Up = Rotation.GetUpVector();
536  DrawDebugSphere(
537  World,
538  Location,
539  50.0f,
540  10,
541  FColor(0, 255, 0),
542  true
543  );
544  }
545 
546  TArray<const cre::RoadInfoSignal*> References;
547  auto waypoints = Map->GenerateWaypointsOnRoadEntries();
548  std::unordered_set<cr::RoadId> ExploredRoads;
549  for (auto & waypoint : waypoints)
550  {
551  // Check if we already explored this road
552  if (ExploredRoads.count(waypoint.road_id) > 0)
553  {
554  continue;
555  }
556  ExploredRoads.insert(waypoint.road_id);
557 
558  // Multiple times for same road (performance impact, not in behavior)
559  auto SignalReferences = Map->GetLane(waypoint).
560  GetRoad()->GetInfos<cre::RoadInfoSignal>();
561  for (auto *SignalReference : SignalReferences)
562  {
563  References.Add(SignalReference);
564  }
565  }
566  for (auto& Reference : References)
567  {
568  auto RoadId = Reference->GetRoadId();
569  const auto* SignalReference = Reference;
570  const FTransform SignalTransform = SignalReference->GetSignal()->GetTransform();
571  for(auto &validity : SignalReference->GetValidities())
572  {
573  for(auto lane : carla::geom::Math::GenerateRange(validity._from_lane, validity._to_lane))
574  {
575  if(lane == 0)
576  continue;
577 
578  auto signal_waypoint = Map->GetWaypoint(
579  RoadId, lane, SignalReference->GetS()).get();
580 
581  if(Map->GetLane(signal_waypoint).GetType() != cr::Lane::LaneType::Driving)
582  continue;
583 
584  FTransform ReferenceTransform = Map->ComputeTransform(signal_waypoint);
585 
586  DrawDebugSphere(
587  World,
588  ReferenceTransform.GetLocation(),
589  50.0f,
590  10,
591  FColor(0, 0, 255),
592  true
593  );
594 
595  DrawDebugLine(
596  World,
597  ReferenceTransform.GetLocation(),
598  SignalTransform.GetLocation(),
599  FColor(0, 0, 255),
600  true
601  );
602  }
603  }
604  }
605 
606 }
607 
608 TArray<FBoundingBox> ACarlaGameModeBase::GetAllBBsOfLevel(uint8 TagQueried) const
609 {
610  UWorld* World = GetWorld();
611 
612  // Get all actors of the level
613  TArray<AActor*> FoundActors;
614  UGameplayStatics::GetAllActorsOfClass(World, AActor::StaticClass(), FoundActors);
615 
616  TArray<FBoundingBox> BoundingBoxes;
617  BoundingBoxes = UBoundingBoxCalculator::GetBoundingBoxOfActors(FoundActors, TagQueried);
618 
619  return BoundingBoxes;
620 }
621 
623 {
624  // Get all actors of the level
625  TArray<AActor*> FoundActors;
626  UGameplayStatics::GetAllActorsOfClass(GetWorld(), AActor::StaticClass(), FoundActors);
627  ObjectRegister->RegisterObjects(FoundActors);
628 }
629 
631  const TSet<uint64>& EnvObjectIds,
632  bool Enable)
633 {
634  ObjectRegister->EnableEnvironmentObjects(EnvObjectIds, Enable);
635 }
636 
637 void ACarlaGameModeBase::LoadMapLayer(int32 MapLayers)
638 {
639  const UWorld* World = GetWorld();
640  UGameplayStatics::FlushLevelStreaming(World);
641 
642  TArray<FName> LevelsToLoad;
643  ConvertMapLayerMaskToMapNames(MapLayers, LevelsToLoad);
644 
645  FLatentActionInfo LatentInfo;
646  LatentInfo.CallbackTarget = this;
647  LatentInfo.ExecutionFunction = "OnLoadStreamLevel";
648  LatentInfo.Linkage = 0;
649  LatentInfo.UUID = LatentInfoUUID;
650 
651  PendingLevelsToLoad = LevelsToLoad.Num();
652 
653  for(FName& LevelName : LevelsToLoad)
654  {
655  LatentInfoUUID++;
656  UGameplayStatics::LoadStreamLevel(World, LevelName, true, true, LatentInfo);
657  LatentInfo.UUID = LatentInfoUUID;
658  UGameplayStatics::FlushLevelStreaming(World);
659  }
660 }
661 
663 {
664  const UWorld* World = GetWorld();
665 
666  TArray<FName> LevelsToUnLoad;
667  ConvertMapLayerMaskToMapNames(MapLayers, LevelsToUnLoad);
668 
669  FLatentActionInfo LatentInfo;
670  LatentInfo.CallbackTarget = this;
671  LatentInfo.ExecutionFunction = "OnUnloadStreamLevel";
672  LatentInfo.UUID = LatentInfoUUID;
673  LatentInfo.Linkage = 0;
674 
675  PendingLevelsToUnLoad = LevelsToUnLoad.Num();
676 
677  for(FName& LevelName : LevelsToUnLoad)
678  {
679  LatentInfoUUID++;
680  UGameplayStatics::UnloadStreamLevel(World, LevelName, LatentInfo, false);
681  LatentInfo.UUID = LatentInfoUUID;
682  UGameplayStatics::FlushLevelStreaming(World);
683  }
684 
685 }
686 
687 void ACarlaGameModeBase::ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray<FName>& OutLevelNames)
688 {
689  UWorld* World = GetWorld();
690  const TArray <ULevelStreaming*> Levels = World->GetStreamingLevels();
691  TArray<FString> LayersToLoad;
692 
693  // Get all the requested layers
694  int32 LayerMask = 1;
695  int32 AllLayersMask = static_cast<crp::MapLayerType>(crp::MapLayer::All);
696 
697  while(LayerMask > 0)
698  {
699  // Convert enum to FString
700  FString LayerName = UTF8_TO_TCHAR(MapLayerToString(static_cast<crp::MapLayer>(LayerMask)).c_str());
701  bool included = static_cast<crp::MapLayerType>(MapLayer) & LayerMask;
702  if(included)
703  {
704  LayersToLoad.Emplace(LayerName);
705  }
706  LayerMask = (LayerMask << 1) & AllLayersMask;
707  }
708 
709  // Get all the requested level maps
710  for(ULevelStreaming* Level : Levels)
711  {
712  TArray<FString> StringArray;
713  FString FullSubMapName = Level->GetWorldAssetPackageFName().ToString();
714  // Discard full path, we just need the umap name
715  FullSubMapName.ParseIntoArray(StringArray, TEXT("/"), false);
716  FString SubMapName = StringArray[StringArray.Num() - 1];
717  for(FString LayerName : LayersToLoad)
718  {
719  if(SubMapName.Contains(LayerName))
720  {
721  OutLevelNames.Emplace(FName(*SubMapName));
722  break;
723  }
724  }
725  }
726 
727 }
728 
729 ULevel* ACarlaGameModeBase::GetULevelFromName(FString LevelName)
730 {
731  ULevel* OutLevel = nullptr;
732  UWorld* World = GetWorld();
733  const TArray <ULevelStreaming*> Levels = World->GetStreamingLevels();
734 
735  for(ULevelStreaming* Level : Levels)
736  {
737  FString FullSubMapName = Level->GetWorldAssetPackageFName().ToString();
738  if(FullSubMapName.Contains(LevelName))
739  {
740  OutLevel = Level->GetLoadedLevel();
741  if(!OutLevel)
742  {
743  UE_LOG(LogCarla, Warning, TEXT("%s has not been loaded"), *LevelName);
744  }
745  break;
746  }
747  }
748 
749  return OutLevel;
750 }
751 
753 {
755 
756  // Register new actors and tag them
758  {
760  ATagger::TagActorsInLevel(*GetWorld(), true);
761  }
762 }
763 
765 {
767  // Update stored registered objects (discarding the deleted objects)
769  {
771  }
772 }
773 
775 {
777 }
void CheckPlayAfterMapLoaded(void)
UObjectRegister * ObjectRegister
TSet< TSubclassOf< ACarlaActorFactory > > ActorFactories
List of actor spawners that will be used to define and spawn the actors available in game...
Base class for Carla actor factories.
int32 GetCurrentMapLayer() const
ACarlaRecorder * Recorder
void ApplyTextureToActor(AActor *Actor, UTexture2D *Texture, const carla::rpc::MaterialParameter &TextureParam)
ULevel * GetULevelFromName(FString LevelName)
sensor::data::Color Color
static TArray< FBoundingBox > GetBoundingBoxOfActors(const TArray< AActor *> &Actors, uint8 InTagQueried=0xFF)
FString MapName
Definition: CarlaEpisode.h:324
void EndPlay(const EEndPlayReason::Type EndPlayReason) override
void SetEpisode(UCarlaEpisode *ThisEpisode)
void ApplyQualityLevelPostRestart()
After loading a level, apply the current settings.
TArray< ACarlaActorFactory * > ActorFactoryInstances
std::vector< cg::Location > Path
static FOnEpisodeSettingsChange OnEpisodeSettingsChange
void DebugShowSignals(bool enable)
FDelegateHandle OnEpisodeSettingsChangeHandle
void SetAllActorsDrawDistance(UWorld *world, float max_draw_distance) const
void NotifyBeginEpisode(UCarlaEpisode &Episode)
void EnableEnvironmentObjects(const TSet< uint64 > &EnvObjectIds, bool Enable)
void RegisterSpawnHandler(UWorld *World)
Create the event trigger handler for all the newly spawned actors to be processed with a custom funct...
UCarlaGameInstance * GameInstance
void EnableEnvironmentObjects(const TSet< uint64 > &EnvObjectIds, bool Enable)
void UnLoadMapLayer(int32 MapLayers)
CarlaReplayer * GetReplayer(void)
AActor * FindActorByName(const FString &ActorName)
UTexture2D * CreateUETexture(const carla::rpc::TextureColor &Texture)
void InitGame(const FString &MapName, const FString &Options, FString &ErrorMessage) override
int GetNumTiles() const
static boost::optional< road::Map > Load(const std::string &opendrive)
ALargeMapManager * LMManager
geom::Location Location
Definition: rpc/Location.h:14
void LoadMapLayer(int32 MapLayers)
static void TagActorsInLevel(UWorld &World, bool bTagForSemanticSegmentation)
Set the tag of every actor in level.
Definition: Tagger.cpp:198
uint16_t MapLayerType
Definition: MapLayer.h:16
carla::SharedPtr< cc::Actor > Actor
void Tick(float DeltaSeconds) override
std::string MapLayerToString(MapLayer MapLayerValue)
Definition: MapLayer.cpp:12
UTaggerDelegate * TaggerDelegate
TArray< FString > GetNamesOfAllActors()
static FString GetXODR(const UWorld *World)
Return the OpenDrive XML associated to MapName, or empty if the file is not found.
T & At(uint32_t x, uint32_t y)
Definition: Texture.h:43
const FString GetRelativeMapPath() const
void RegisterActorFactory(ACarlaActorFactory &ActorFactory)
Definition: CarlaEpisode.h:301
AWeather * Weather
Definition: CarlaEpisode.h:336
TArray< FTransform > SpawnPointsTransforms
void SetRecorder(ACarlaRecorder *Rec)
Definition: CarlaEpisode.h:276
boost::optional< carla::road::Map > Map
geom::Rotation Rotation
Definition: rpc/Transform.h:14
carla::geom::GeoLocation MapGeoReference
Definition: CarlaEpisode.h:340
TSubclassOf< AWeather > WeatherClass
The class of Weather to spawn.
static std::vector< int > GenerateRange(int a, int b)
Definition: Math.cpp:151
void RestartPlayer(AController *NewPlayer) override
UCarlaSettingsDelegate * CarlaSettingsDelegate
TArray< FBoundingBox > GetAllBBsOfLevel(uint8 TagQueried=0xFF) const
uint32_t GetHeight() const
Definition: Texture.h:33
void Reset()
Reset settings to default.
void SetSemanticSegmentationEnabled(bool Enable=true)
void RegisterObjects(TArray< AActor *> Actors)
void InitializeAtBeginPlay()
Vector3D GetUpVector() const
Definition: Rotation.h:58
void RegisterSpawnHandler(UWorld *World)
UCarlaEpisode * Episode
ATrafficLightManager * GetTrafficLightManager()
const FString GetFullMapPath() const
void ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray< FName > &OutLevelNames)
geom::Transform Transform
Definition: rpc/Transform.h:16
void ApplyWeather(const FWeatherParameters &WeatherParameters)
Update the weather parameters and notifies it to the blueprint&#39;s event.
Definition: Weather.cpp:17
uint32_t GetWidth() const
Definition: Texture.h:29
void ApplyQualityLevelPreRestart()
Before loading a level, apply the current settings.
void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings)
ACarlaGameModeBase(const FObjectInitializer &ObjectInitializer)
ATrafficLightManager * TrafficLightManager
Class In charge of creating and assigning traffic light groups, controllers and components.
void BeginPlay() override