17 #include "GameFramework/Controller.h" 34 UE_LOG(LogCarla, Warning, TEXT(
"Invalid definition '%s' ignored"), *Definition.
Id);
43 return ActorFactory.
SpawnActor(Transform, Description);
55 UE_LOG(LogCarla, Error, TEXT(
"Invalid ActorDescription '%s' (UId=%d)"), *Description.
Id, Description.
UId);
56 return MakeTuple(EActorSpawnResultStatus::InvalidDescription,
nullptr);
59 UE_LOG(LogCarla, Log, TEXT(
"Spawning actor '%s'"), *Description.
Id);
64 if ((Result.
Status == EActorSpawnResultStatus::Success) && (Result.
Actor ==
nullptr))
66 UE_LOG(LogCarla, Warning, TEXT(
"ActorSpawnResult: Trying to spawn '%s'"), *Description.
Id);
67 UE_LOG(LogCarla, Warning, TEXT(
"ActorSpawnResult: Reported success but did not return an actor"));
68 Result.
Status = EActorSpawnResultStatus::UnknownError;
75 UE_LOG(LogCarla, Warning, TEXT(
"Failed to spawn actor '%s'"), *Description.
Id);
76 check(Result.
Status != EActorSpawnResultStatus::Success);
83 return MakeTuple(Result.
Status, View);
92 UE_LOG(LogCarla, Error, TEXT(
"Invalid ActorDescription '%s' (UId=%d)"), *Description.
Id, Description.
UId);
96 UE_LOG(LogCarla, Log, TEXT(
"Spawning actor '%s'"), *Description.
Id);
101 if ((Result.
Status == EActorSpawnResultStatus::Success) && (Result.
Actor ==
nullptr))
103 UE_LOG(LogCarla, Warning, TEXT(
"ActorSpawnResult: Trying to spawn '%s'"), *Description.
Id);
104 UE_LOG(LogCarla, Warning, TEXT(
"ActorSpawnResult: Reported success but did not return an actor"));
105 Result.
Status = EActorSpawnResultStatus::UnknownError;
109 if (Result.
Status == EActorSpawnResultStatus::Success)
125 UE_LOG(LogCarla, Warning, TEXT(
"Trying to destroy actor that is not in the registry"));
136 AController* Controller = (Pawn !=
nullptr ? Pawn->GetController() :
nullptr);
137 if (Controller !=
nullptr)
139 UE_LOG(LogCarla, Log, TEXT(
"Destroying actor's controller: '%s'"), *Id);
140 bool Success = Controller->Destroy();
143 UE_LOG(LogCarla, Error, TEXT(
"Failed to destroy actor's controller: '%s'"), *Id);
148 UE_LOG(LogCarla, Log, TEXT(
"UActorDispatcher::Destroying actor: '%s' %x"), *Id, Actor);
149 UE_LOG(LogCarla, Log, TEXT(
" %s"), Actor?*Actor->GetName():*FString(
"None"));
150 if (!Actor || !Actor->Destroy())
152 UE_LOG(LogCarla, Error, TEXT(
"Failed to destroy actor: '%s'"), *Id);
173 #if defined(WITH_ROS2) 175 if (ROS2->IsEnabled())
181 if (Attr.Key ==
"ros_name")
183 RosName = std::string(TCHAR_TO_UTF8(*Attr.Value.Value));
186 const std::string
id = std::string(TCHAR_TO_UTF8(*Description.
Id));
188 if(RosName.find(
"vehicle") != std::string::npos)
190 std::string VehicleName =
"vehicle" + std::to_string(View->
GetActorId());
191 ROS2->AddActorRosName(static_cast<void*>(&Actor), VehicleName);
195 size_t pos = RosName.find_last_of(
'.');
196 if (pos != std::string::npos) {
197 std::string lastToken = RosName.substr(pos + 1) +
"__";
198 ROS2->AddActorRosName(static_cast<void*>(&Actor), lastToken);
202 ROS2->AddActorRosName(static_cast<void*>(&Actor), RosName);
208 if (Attr.Key ==
"role_name" && (Attr.Value.Value ==
"hero" || Attr.Value.Value ==
"ego"))
214 boost::variant2::visit(Handler, Data);
245 #if defined(WITH_ROS2) 247 if (ROS2->IsEnabled())
249 ROS2->RemoveActorRosName(reinterpret_cast<void *>(Actor));
Base class for Carla actor factories.
void Deregister(IdType Id)
void Bind(FActorDefinition Definition, SpawnFunctionType SpawnFunction)
Bind a definition to a spawn function.
TArray< TSubclassOf< AActor > > Classes
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActor(const FTransform &Transform, FActorDescription ActorDescription, FCarlaActor::IdType DesiredId=0)
Spawns an actor based on ActorDescription at Transform.
void PutActorToSleep(IdType Id, UCarlaEpisode *CarlaEpisode)
AActor * ReSpawnActor(const FTransform &Transform, FActorDescription ActorDescription)
ReSpawns an actor based on ActorDescription at Transform.
void OnActorDestroyed(AActor *Actor)
bool DestroyActor(FCarlaActor::IdType ActorId)
Destroys an actor, properly removing it from the registry.
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...
uint32 UId
Uniquely identifies the definition (no need to fill it).
TFunction< FActorSpawnResult(const FTransform &, const FActorDescription &)> SpawnFunctionType
A definition of a Carla Actor with all the variation and attributes.
void WakeActorUp(IdType Id, UCarlaEpisode *CarlaEpisode)
static bool CheckActorDefinition(const FActorDefinition &ActorDefinitions)
Return whether the actor definition is valid. Prints all the errors found.
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
TArray< FActorDefinition > Definitions
carla::SharedPtr< cc::Actor > Actor
FString Id
Display ID that identifies the actor.
TSubclassOf< AActor > Class
Class of the actor to be spawned.
A description of a Carla Actor with all its variation.
boost::variant2::variant< VehicleControl > ROS2CallbackData
FActorDescription Description
const FActorInfo * GetActorInfo() const
virtual TArray< FActorDefinition > GetDefinitions()
Retrieve the list of actor definitions that this class is able to spawn.
virtual FActorSpawnResult SpawnActor(const FTransform &SpawnAtTransform, const FActorDescription &ActorDescription)
Spawn an actor based on ActorDescription and Transform.
FCarlaActor::IdType IdType
TArray< SpawnFunctionType > SpawnFunctions
FString Id
Display ID that identifies the actor.
uint32 UId
UId of the definition in which this description was based.
void WakeActorUp(FCarlaActor::IdType Id, UCarlaEpisode *CarlaEpisode)
FCarlaActor * Register(AActor &Actor, FActorDescription Description, IdType DesiredId=0)
Register the Actor in the database.
static std::shared_ptr< ROS2 > GetInstance()
static void TagActor(const AActor &Actor, bool bTagForSemanticSegmentation)
Set the tag of an actor.
IdType GetActorId() const
TSubclassOf< AActor > Class
Class of the actor to be spawned (Optional).
FCarlaActor * FindCarlaActor(IdType Id)
EActorSpawnResultStatus Status
Result of an actor spawn function.
geom::Transform Transform
A view over an actor and its properties.
void PutActorToSleep(FCarlaActor::IdType Id, UCarlaEpisode *CarlaEpisode)