CARLA
Loading...
Searching...
No Matches
RoutePlanner.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
9#include <util/ue-header-guard-begin.h>
10#include "GameFramework/Actor.h"
11#include "Components/BoxComponent.h"
12#include "Components/SplineComponent.h"
13#include <util/ue-header-guard-end.h>
14
15#include "RoutePlanner.generated.h"
16
18
19/// Assign a random route to every ACarlaWheeledVehicle entering the trigger
20/// volume. Routes must be added in editor after placing this actor into the
21/// world. Spline tangents are ignored, only locations are taken into account
22/// for making the route.
23UCLASS()
24class CARLA_API ARoutePlanner : public AActor
25{
26 GENERATED_BODY()
27
28public:
29
30 ARoutePlanner(const FObjectInitializer &ObjectInitializer);
31
32 virtual void BeginDestroy() override;
33
34 void Init();
35
36 void SetBoxExtent(const FVector &Extent)
37 {
38 TriggerVolume->SetBoxExtent(Extent);
39 }
40
41 void DrawRoutes();
42
43 void AddRoute(float probability, const TArray<FVector> &routePoints);
44
45 void CleanRoute();
46
47 void AssignRandomRoute(AWheeledVehicleAIController &Controller) const;
48
49 /// Searches every ARoutePlanner in the world for the route spline point
50 /// closest to Location, and returns the road direction there (as a
51 /// rotator built from the spline tangent). Used by editor tools that want
52 /// to align spawned props (e.g. road decals) to the flow of traffic.
53 /// Returns false, leaving OutRotation untouched, if no route spline point
54 /// is found within SearchRadius.
55 UFUNCTION(BlueprintCallable, Category = "Traffic Routes", meta = (WorldContext = "WorldContextObject"))
56 static bool FindRoadFlowRotationAtLocation(
57 const UObject *WorldContextObject,
58 const FVector &Location,
59 float SearchRadius,
60 FRotator &OutRotation);
61
62protected:
63
64#if WITH_EDITOR
65 virtual void PostEditChangeProperty(FPropertyChangedEvent &PropertyChangedEvent) override;
66
67#endif // WITH_EDITOR
68
69 virtual void BeginPlay() override;
70
71 virtual void EndPlay(EEndPlayReason::Type EndPlayReason) override;
72
73 UFUNCTION()
74 void OnTriggerBeginOverlap(
75 UPrimitiveComponent *OverlappedComp,
76 AActor *OtherActor,
77 UPrimitiveComponent *OtherComp,
78 int32 OtherBodyIndex,
79 bool bFromSweep,
80 const FHitResult &SweepResult);
81
82public:
83
84 UPROPERTY(EditAnywhere)
85 TObjectPtr<UBoxComponent> TriggerVolume;
86
87 UPROPERTY(BlueprintReadWrite, Category = "Traffic Routes", EditAnywhere)
88 TArray<TObjectPtr<USplineComponent>> Routes;
89
90 UPROPERTY(BlueprintReadWrite, Category = "Traffic Routes", EditAnywhere, EditFixedSize)
91 TArray<float> Probabilities;
92
93 UPROPERTY(BlueprintReadWrite, Category = "Traffic Routes", EditAnywhere, EditFixedSize)
94 bool bIsIntersection = false;
95};
Assign a random route to every ACarlaWheeledVehicle entering the trigger volume.
void SetBoxExtent(const FVector &Extent)
Wheeled vehicle controller with optional AI.