CARLA
Loading...
Searching...
No Matches
TriggerFactory.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
8#include "Carla.h"
15
16// =============================================================================
17// -- ATriggerFactory -----------------------------------------------------------
18// =============================================================================
19
20TArray<FActorDefinition> ATriggerFactory::GetDefinitions()
21{
22 FActorDefinition TriggerDefinition = FActorDefinition();
23 TriggerDefinition.Class = AFrictionTrigger::StaticClass();
24
25 TArray<FActorDefinition> TriggerDefinitions;
26
27 bool Success;
28 UActorBlueprintFunctionLibrary::MakeTriggerDefinition(TEXT("friction"), Success, TriggerDefinition);
29 check(Success);
30 TriggerDefinitions.Add(TriggerDefinition);
31
32 return TriggerDefinitions;
33}
34
36 const FTransform &Transform,
37 const FActorDescription &Description)
38{
39 auto *World = GetWorld();
40 if (World == nullptr)
41 {
42 UE_LOG(LogCarla, Error, TEXT("ATriggerFactory: cannot spawn trigger into an empty world."));
43 return {};
44 }
45
47 if (GameInstance == nullptr)
48 {
49 UE_LOG(LogCarla, Error, TEXT("ATriggerFactory:: cannot spawn trigger, incompatible game instance."));
50 return {};
51 }
52
53 auto *Trigger = World->SpawnActorDeferred<AFrictionTrigger>(
54 Description.Class,
55 Transform,
56 this,
57 nullptr,
58 ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
59
60 if (Trigger == nullptr)
61 {
62 UE_LOG(LogCarla, Error, TEXT("ATriggerFactory:: spawn trigger failed."));
63 }
64 else
65 {
66 // Retrieve Episode
67 auto *Episode = GameInstance->GetCarlaEpisode();
68 check(Episode != nullptr);
69 Trigger->SetEpisode(*Episode);
70
71 // Retrieve Friction
73 Description.Variations,
74 3.5f);
75 Trigger->SetFriction(Friction);
76
77 // Retrieve Extent
78 FVector Extent {100.0f, 100.0f, 100.0f};
79
81 Description.Variations,
82 Extent.X);
84 Description.Variations,
85 Extent.Y);
87 Description.Variations,
88 Extent.Z);
89
90 Trigger->SetBoxExtent(Extent);
91 }
92 UGameplayStatics::FinishSpawningActor(Trigger, Transform);
93 return FActorSpawnResult{Trigger};
94}
TArray< FActorDefinition > GetDefinitions() final
Retrieve the definitions of all the sensors registered in the SensorRegistry.
FActorSpawnResult SpawnActor(const FTransform &SpawnAtTransform, const FActorDescription &ActorDescription) final
Spawn an actor based on ActorDescription and Transform.
static void MakeTriggerDefinition(const FString &Id, bool &Success, FActorDefinition &Definition)
static float RetrieveActorAttributeToFloat(const FString &Id, const TMap< FString, FActorAttribute > &Attributes, float Default)
The game instance contains elements that must be kept alive in between levels.
UCarlaEpisode * GetCarlaEpisode()
static UCarlaGameInstance * GetGameInstance(const UObject *WorldContextObject)
A definition of a Carla Actor with all the variation and attributes.
TSubclassOf< AActor > Class
Class of the actor to be spawned (Optional).
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.
Result of an actor spawn function.