CARLA
Loading...
Searching...
No Matches
CarlaGameModeBase.h
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
7#pragma once
8
20
22#include <carla/rpc/Texture.h>
25
26#include <util/ue-header-guard-begin.h>
27#include "CoreMinimal.h"
28#include "GameFramework/GameModeBase.h"
30#include <util/ue-header-guard-end.h>
31
32#include <optional>
33
34#include "CarlaGameModeBase.generated.h"
35
36DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEpisodeInitialisedDelegate, UCarlaEpisode*, InitialisedEpisode);
37
38/// Base class for the CARLA Game Mode.
39UCLASS(HideCategories=(ActorTick))
40class CARLA_API ACarlaGameModeBase : public AGameModeBase
41{
42 GENERATED_BODY()
43
44public:
45
46 ACarlaGameModeBase(const FObjectInitializer& ObjectInitializer);
47
49 {
50 check(Episode != nullptr);
51 return *Episode;
52 }
53
54 const std::optional<carla::road::Map>& GetMap() const {
55 return Map;
56 }
57
58 const FString GetFullMapPath() const;
59
60 // get path relative to Content folder
61 const FString GetRelativeMapPath() const;
62
63 UFUNCTION(Exec, Category = "CARLA Game Mode")
64 void DebugShowSignals(bool enable);
65
66 UFUNCTION(BlueprintCallable, Category = "CARLA Game Mode")
67 ATrafficLightManager* GetTrafficLightManager();
68
69 UFUNCTION(Category = "Carla Game Mode", BlueprintCallable)
70 const TArray<FTransform>& GetSpawnPointsTransforms() const{
72 }
73
74 UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec)
75 TArray<FBoundingBox> GetAllBBsOfLevel(uint8 TagQueried = 0xFF) const;
76
77 UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec)
78 TArray<FEnvironmentObject> GetEnvironmentObjects(uint8 QueriedTag = 0xFF) const
79 {
80 return ObjectRegister->GetEnvironmentObjects(QueriedTag);
81 }
82
83 void EnableEnvironmentObjects(const TSet<uint64>& EnvObjectIds, bool Enable);
84
85 /// The registered environment objects disabled now, and a count of the
86 /// changes to that set: Multi-GPU secondaries mirror it.
87 const TSet<uint64> &GetDisabledEnvironmentObjects() const
88 {
90 }
91
93 {
95 }
96
97 /// How many times the environment objects were registered (on every map
98 /// layer streamed in or out).
103
104 /// rpc::MapLayer bits of the layers loaded now.
105 int32 GetLoadedMapLayers() const
106 {
107 return LoadedMapLayers;
108 }
109
110 void EnableOverlapEvents();
111
112 void CheckForEmptyMeshes();
113
114 UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec)
115 void LoadMapLayer(int32 MapLayers);
116
117 UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec)
118 void UnLoadMapLayer(int32 MapLayers);
119
120 UFUNCTION(Category = "Carla Game Mode")
121 ULevel* GetULevelFromName(FString LevelName);
122
123 UFUNCTION(BlueprintCallable, Category = "Carla Game Mode")
124 void OnLoadStreamLevel();
125
126 UFUNCTION(BlueprintCallable, Category = "Carla Game Mode")
127 void OnUnloadStreamLevel();
128
130 return LMManager;
131 }
132
133 AActor* FindActorByName(const FString& ActorName);
134
135 UTexture2D* CreateUETexture(const carla::rpc::TextureColor& Texture);
136 UTexture2D* CreateUETexture(const carla::rpc::TextureFloatColor& Texture);
137
138 void ApplyTextureToActor(
139 AActor* Actor,
140 UTexture2D* Texture,
141 const carla::rpc::MaterialParameter& TextureParam);
142
143 [[deprecated("This command no longer makes sense since the apply_textures API relies on IDs.")]]
144 TArray<FString> GetNamesOfAllActors();
145
146 /// Gravitational acceleration used by IMU sensors.
147 /// Default is Earth's, approximately 9.81 m/s^2.
148 UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Sensor Gravity")
149 float IMUSensorGravity = 9.81f;
150
151 FOnEpisodeInitialisedDelegate OnEpisodeInitialisedDelegate;
152
153protected:
154
155 void InitGame(const FString &MapName, const FString &Options, FString &ErrorMessage) override;
156
157 void RestartPlayer(AController *NewPlayer) override;
158
159 void BeginPlay() override;
160
161 void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
162
163 void Tick(float DeltaSeconds) override;
164
165 /// Loads the episode georeference (parsing the map's OpenDRIVE by default)
166 /// and stores the recommended spawn points. Virtual so Autoware maps can
167 /// take the georeference from an MGRS data asset instead (tier4 port).
168 virtual void LoadGeoReference();
169
170 void StoreSpawnPoints();
171
172 UPROPERTY()
174
175private:
176
177 /// Tags actors of World Partition cells as they stream in. The legacy
178 /// ALargeMapManager used to do this for WorldComposition tiles, but it
179 /// retires itself on World Partition maps, which left streamed-in cells
180 /// untagged (semantic segmentation rendered them unlabeled).
181 void OnLevelAddedToWorld(ULevel* InLevel, UWorld* InWorld);
182
183 void SpawnActorFactories();
184
185 void GenerateSpawnPoints();
186
187 void ParseOpenDrive();
188
189public:
190
191 // Public so map managers can refresh environment objects after relocating
192 // actors (e.g. traffic sign height adjustment).
194
195private:
196
197 void ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray<FName>& OutLevelNames);
198
199 void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings);
200
201 UPROPERTY()
203
204 UPROPERTY()
206
207 UPROPERTY()
209
210 UPROPERTY()
212
213 UPROPERTY()
215
216 /// The class of Weather to spawn.
217 UPROPERTY(Category = "CARLA Game Mode", EditAnywhere)
218 TSubclassOf<AWeather> WeatherClass;
219
220 /// List of actor spawners that will be used to define and spawn the actors
221 /// available in game.
222 UPROPERTY(Category = "CARLA Game Mode", EditAnywhere)
224
225 UPROPERTY()
226 TArray<FTransform> SpawnPointsTransforms;
227
228 UPROPERTY()
230
231 UPROPERTY()
233
235
237
238 std::optional<carla::road::Map> Map;
239
241
243
245
247
250
252
253 // We keep a global uuid to allow the load/unload layer methods to be called
254 // in the same tick
255 int32 LatentInfoUUID = 0;
256
257};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEpisodeInitialisedDelegate, UCarlaEpisode *, InitialisedEpisode)
Base class for Carla actor factories.
TSubclassOf< AWeather > WeatherClass
The class of Weather to spawn.
const std::optional< carla::road::Map > & GetMap() const
TArray< FTransform > SpawnPointsTransforms
uint64 GetEnvironmentObjectsRegistrations() const
How many times the environment objects were registered (on every map layer streamed in or out).
std::optional< carla::road::Map > Map
TArray< ACarlaActorFactory * > ActorFactoryInstances
float IMUSensorGravity
Gravitational acceleration used by IMU sensors.
void BeginPlay() override
UCarlaGameInstance * GameInstance
TArray< FEnvironmentObject > GetEnvironmentObjects(uint8 QueriedTag=0xFF) const
UCarlaSettingsDelegate * CarlaSettingsDelegate
void InitGame(const FString &MapName, const FString &Options, FString &ErrorMessage) override
ALargeMapManager * LMManager
void RestartPlayer(AController *NewPlayer) override
uint64 GetEnvironmentObjectsSerial() const
FOnEpisodeInitialisedDelegate OnEpisodeInitialisedDelegate
ALargeMapManager * GetLMManager() const
ACarlaRecorder * Recorder
TSet< uint64 > DisabledEnvironmentObjects
const TArray< FTransform > & GetSpawnPointsTransforms() const
void EndPlay(const EEndPlayReason::Type EndPlayReason) override
const UCarlaEpisode & GetCarlaEpisode() const
void OnLevelAddedToWorld(ULevel *InLevel, UWorld *InWorld)
Tags actors of World Partition cells as they stream in.
FDelegateHandle OnEpisodeSettingsChangeHandle
void ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray< FName > &OutLevelNames)
UTaggerDelegate * TaggerDelegate
const TSet< uint64 > & GetDisabledEnvironmentObjects() const
The registered environment objects disabled now, and a count of the changes to that set: Multi-GPU se...
ATrafficLightManager * TrafficLightManager
UObjectRegister * ObjectRegister
void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings)
UCarlaEpisode * Episode
void Tick(float DeltaSeconds) override
int32 GetLoadedMapLayers() const
rpc::MapLayer bits of the layers loaded now.
ACarlaGameModeBase(const FObjectInitializer &ObjectInitializer)
TSet< TSubclassOf< ACarlaActorFactory > > ActorFactories
List of actor spawners that will be used to define and spawn the actors available in game.
virtual void LoadGeoReference()
Loads the episode georeference (parsing the map's OpenDRIVE by default) and stores the recommended sp...
Recorder for the simulation.
Class In charge of creating and assigning traffic light groups, controllers and components.
A simulation episode.
The game instance contains elements that must be kept alive in between levels.
Used to set settings for every actor that is spawned into the world.
Used to tag every actor that is spawned into the world.
Texture< sensor::data::Color > TextureColor
Definition Texture.h:66
Texture< FloatColor > TextureFloatColor
Definition Texture.h:67
This file contains definitions of common data structures used in traffic manager.