UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
RecastGraphAStar.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
9#include "GraphAStar.h"
11
12#include "RecastGraphAStar.generated.h"
13
15{
16 static const int32 NodePoolSize = 2048;
17 static const int32 OpenSetSize = 2048;
18 static const int32 FatalPathLength = 10000;
19 static const bool bReuseNodePoolInSubsequentSearches = false;
20};
21
22class ARecastNavMesh;
26struct FRecastAStar;
27
29typedef unsigned int dtStatus;
30struct dtPoly;
31struct dtMeshTile;
32struct dtLink;
33class dtNavMesh;
34
35#if WITH_RECAST
37{
40
41 inline operator dtPolyRef() const
42 {
43 return NodeRef;
44 }
45
46protected:
47 inline FRecastNeighbour(dtPolyRef InNodeRef, unsigned char InSide = 0)
48 : NodeRef{ InNodeRef }
49 , Side{ InSide }
50 {}
51public:
52 dtPolyRef NodeRef;
53 unsigned char Side;
54};
55
57{
58 void Reset(const int32 PathLength)
59 {
60 data.resize(0);
61 }
62 void AddZeroed(const int32 PathLength)
63 {
64 data.resize(PathLength);
65 }
66
68};
69#endif // WITH_RECAST
70
71USTRUCT()
73{
75
76public:
78
79#if WITH_RECAST
82
85
87 // FGraphAStar: TGraph
88 typedef dtPolyRef FNodeRef;
89
90 inline bool IsValidRef(const dtPolyRef& NodeRef) const
91 {
92 return NodeRef != INVALID_NAVNODEREF;
93 }
94 AIMODULE_API FRecastNeighbour GetNeighbour(const FRecastAStarSearchNode& Node, const int32 NeighbourIndex) const;
96
97 inline const dtNavMeshQuery& GetRecastQuery() const { return RecastQuery; }
98
99protected:
100
103
104 inline const ARecastNavMesh* GetRecastNavMeshActor() const { checkSlow(RecastNavMeshActor); return RecastNavMeshActor; }
105 inline const dtNavMesh* GetDetourNavMesh() const { checkSlow(DetourNavMesh); return DetourNavMesh; }
107#endif // WITH_RECAST
108
109private:
111 TObjectPtr<const ARecastNavMesh> RecastNavMeshActor = nullptr;
112
113#if WITH_RECAST
114 const dtNavMesh* DetourNavMesh = nullptr;
115
117
118 mutable unsigned int CachedNextLink = DT_NULL_LINK;
119#endif // WITH_RECAST
120};
121
122#if WITH_RECAST
123struct FRecastAStarSearchNode : public FGraphAStarDefaultNode<FRecastGraphWrapper>
124{
126
128 : Super(InNodeRef)
129 , Tile{ nullptr }
130 , Poly{ nullptr }
132 {}
133
135 FGraphAStarDefaultNode& operator=(const FGraphAStarDefaultNode& Other) = delete;
136
137 mutable const dtMeshTile* Tile;
138 mutable const dtPoly* Poly;
139 mutable FVector::FReal Position[3]; // Position in Recast World coordinate system
140
141 inline operator dtPolyRef() const
142 {
143 return NodeRef;
144 }
145
146 inline void Initialize(const FRecastGraphWrapper& RecastGraphWrapper) const
147 {
148 RecastGraphWrapper.GetDetourNavMesh()->getTileAndPolyByRefUnsafe(NodeRef, &Tile, &Poly);
149 }
150
151 inline bool HasValidCacheInfo() const
152 {
154 }
155
156 inline void CacheInfo(const FRecastGraphWrapper& RecastGraphWrapper, const FRecastAStarSearchNode& FromNode) const
157 {
158 checkSlow(FromNode.HasValidCacheInfo());
159 if (!HasValidCacheInfo())
160 {
162 RecastGraphWrapper.GetRecastQuery().getEdgeMidPoint(FromNode.NodeRef, FromNode.Poly, FromNode.Tile, NodeRef, Poly, Tile, Position);
163 }
164 }
165};
166
167struct FRecastAStar : public FGraphAStar<FRecastGraphWrapper, FRecastGraphPolicy, FRecastAStarSearchNode>
168{
171 : Super(Graph)
172 {}
173};
174
176{
178
179 inline bool WantsPartialSolution() const
180 {
181 return true;
182 }
183 inline FVector::FReal GetHeuristicScale() const
184 {
185 return Filter.getHeuristicScale();
186 }
187
188 inline FVector::FReal GetHeuristicCost(const FRecastAStarSearchNode& StartNode, const FRecastAStarSearchNode& EndNode) const
189 {
190 check(EndNode.HasValidCacheInfo());
191
192 const FVector::FReal Cost = dtVdist(StartNode.Position, EndNode.Position);
193
194 return Cost;
195 }
196
197 inline FVector::FReal GetTraversalCost(const FRecastAStarSearchNode& StartNode, const FRecastAStarSearchNode& EndNode) const
198 {
199 EndNode.CacheInfo(RecastGraphWrapper, StartNode);
200 const FVector::FReal Cost = Filter.getCost(
201 StartNode.Position, EndNode.Position,
202 INVALID_NAVNODEREF, nullptr, nullptr,
203 StartNode.NodeRef, StartNode.Tile, StartNode.Poly,
204 EndNode.NodeRef, EndNode.Tile, EndNode.Poly);
205
206 return Cost;
207 }
208
209 inline bool IsTraversalAllowed(const dtPolyRef& NodeA, const FRecastNeighbour& NodeB) const
210 {
211 if (!Filter.isValidLinkSide(NodeB.Side))
212 {
213 return false;
214 }
215 const dtMeshTile* TileB;
216 const dtPoly* PolyB;
217 RecastGraphWrapper.GetDetourNavMesh()->getTileAndPolyByRefUnsafe(NodeB.NodeRef, &TileB, &PolyB);
218 return Filter.passFilter(NodeB.NodeRef, TileB, PolyB) && RecastGraphWrapper.GetRecastQuery().passLinkFilterByRef(TileB, NodeB.NodeRef);
219 }
220
221 inline bool ShouldIgnoreClosedNodes() const
222 {
223 return Filter.getShouldIgnoreClosedNodes();
224 }
225
226 inline bool ShouldIncludeStartNodeInPath() const
227 {
228 return true;
229 }
230
231 inline uint32 GetMaxSearchNodes() const
232 {
233 return MaxSearchNodes;
234 }
235
236 inline FVector::FReal GetCostLimit() const
237 {
238 return CostLimit;
239 }
240
241protected:
243 friend FRecastGraphWrapper;
244
245 inline const FRecastQueryFilter& GetFilter() const { return Filter; }
247
248private:
252 uint32 MaxSearchNodes;
253 FVector::FReal CostLimit;
254};
255#endif // WITH_RECAST
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
dtReal dtVdist(const dtReal *v1, const dtReal *v2)
Definition DetourCommon.h:304
const unsigned int DT_NULL_LINK
A value that indicates the entity does not link to anything.
Definition DetourNavMesh.h:110
bool IsValidRef(const FVertexBufferAndSRV &Buffer)
Definition GPUSkinVertexFactory.h:92
EGraphAStarResult
Definition GraphAStar.h:16
#define FVector
Definition IOSSystemIncludes.h:8
#define INVALID_NAVNODEREF
Definition NavigationTypes.h:35
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
unsigned int dtStatus
Definition RecastGraphAStar.h:29
uint64 dtPolyRef
Definition RecastGraphAStar.h:28
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition RecastNavMesh.h:574
Definition Object.h:95
Definition DetourNavMeshQuery.h:349
Definition DetourNavMesh.h:503
Definition ParallelSort.h:13
U16 Index
Definition radfft.cpp:71
Definition GraphAStar.h:39
Definition GraphAStar.h:191
Definition RecastGraphAStar.h:15
static const int32 NodePoolSize
Definition RecastGraphAStar.h:16
static const int32 FatalPathLength
Definition RecastGraphAStar.h:18
static const bool bReuseNodePoolInSubsequentSearches
Definition RecastGraphAStar.h:19
static const int32 OpenSetSize
Definition RecastGraphAStar.h:17
Definition RecastGraphAStar.h:73
FRecastGraphWrapper()
Definition RecastGraphAStar.h:77
Definition NumericLimits.h:41
Definition ObjectPtr.h:488
double FReal
Definition Vector.h:55
Definition DetourNavMesh.h:422
Definition DetourNavMesh.h:206
Definition DetourNavMeshQuery.h:316