CARLA
Loading...
Searching...
No Matches
CarlaNavigationSubsystem.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"
10
11#include <util/ue-header-guard-begin.h>
12#include "NavigationSystem.h"
13#include "NavMesh/RecastNavMesh.h"
14#include <util/ue-header-guard-end.h>
15
17{
18 const UNavigationSystemV1 *NavSys =
19 FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
20 if (NavSys == nullptr)
21 {
22 return false;
23 }
24 const ARecastNavMesh *NavMesh =
25 Cast<ARecastNavMesh>(NavSys->GetDefaultNavDataInstance());
26 return (NavMesh != nullptr) && NavMesh->HasValidNavmesh();
27}
28
30{
31 UNavigationSystemV1 *NavSys =
32 FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
33 if (NavSys == nullptr)
34 {
35 return false;
36 }
37 // Sample with the non-crossing walker filter so random locations land on
38 // sidewalk/terrain polys, never on the roadway -- matching the legacy
39 // get_random_location_from_navigation semantics. On navmeshes built before
40 // the road/crosswalk areas existed the filter simply has no effect.
41 FSharedConstNavQueryFilter QueryFilter;
42 if (ANavigationData *NavData = NavSys->GetDefaultNavDataInstance())
43 {
44 QueryFilter = UNavigationQueryFilter::GetQueryFilter(
45 *NavData, TSubclassOf<UNavigationQueryFilter>(UCarlaWalkerNavFilter::StaticClass()));
46 }
47 FNavLocation Result;
48 if (!NavSys->GetRandomPoint(Result, nullptr, QueryFilter))
49 {
50 return false;
51 }
52 OutLocation = Result.Location;
53 return true;
54}
bool GetRandomNavLocation(FVector &OutLocation) const
Random point on the loaded navmesh, in world-local centimeters.
bool HasServerSideNavigation() const
True iff the current world has a RecastNavMesh with valid nav data: the signal for clients that walke...