UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DetourCrowd.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2// Modified version of Recast/Detour's source file
3
4//
5// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
6//
7// This software is provided 'as-is', without any express or implied
8// warranty. In no event will the authors be held liable for any damages
9// arising from the use of this software.
10// Permission is granted to anyone to use this software for any purpose,
11// including commercial applications, and to alter it and redistribute it
12// freely, subject to the following restrictions:
13// 1. The origin of this software must not be misrepresented; you must not
14// claim that you wrote the original software. If you use this software
15// in a product, an acknowledgment in the product documentation would be
16// appreciated but is not required.
17// 2. Altered source versions must be plainly marked as such, and must not be
18// misrepresented as being the original software.
19// 3. This notice may not be removed or altered from any source distribution.
20//
21
22#ifndef DETOURCROWD_H
23#define DETOURCROWD_H
24
25#include "Containers/Map.h"
26#include "CoreMinimal.h"
35#include "HAL/Platform.h"
37
38class FString;
39class dtProximityGrid;
40
44static const int DT_CROWDAGENT_MAX_NEIGHBOURS = 6;
45
51static const int DT_CROWDAGENT_MAX_CORNERS = 4;
52
58static const int DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS = 8;
59
61static const int DT_CROWD_MAX_FILTERS = 16;
62
67{
68 int idx;
70};
71
81
126
137
141{
144
147
150
152 dtCrowdNeighbour neis[DT_CROWDAGENT_MAX_NEIGHBOURS];
153
156
162
165
167 dtReal cornerVerts[DT_CROWDAGENT_MAX_CORNERS*3];
168
170 dtPolyRef cornerPolys[DT_CROWDAGENT_MAX_CORNERS];
171
176
178 int nneis;
179
181 unsigned char cornerFlags[DT_CROWDAGENT_MAX_CORNERS];
182
185
186 unsigned char targetReplan;
187 unsigned char targetState;
188
190 unsigned char active;
191
193 unsigned char state;
194};
195
203
218
219// [UE] Flags used by boundary segments (dtLocalBoundary::Segment)
224
232
236{
237 int m_maxAgents;
238 int m_numActiveAgents;
239 dtCrowdAgent* m_agents;
240 dtCrowdAgent** m_activeAgents;
241 dtCrowdAgentAnimation* m_agentAnims;
242
243 dtPathQueue m_pathq;
244 dtSharedBoundary m_sharedBoundary;
245
246 dtObstacleAvoidanceParams m_obstacleQueryParams[DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS];
247 dtObstacleAvoidanceQuery* m_obstacleQuery;
248
249 dtProximityGrid* m_grid;
250
251 dtPolyRef* m_pathResult;
252
253 dtReal m_ext[3];
254 dtQueryFilter m_filters[DT_CROWD_MAX_FILTERS];
255 dtQueryFilter m_raycastFilter;
256
257 dtReal m_maxAgentRadius;
258
259 // [UE] time between attempts to restore agents state
260 dtReal m_agentStateCheckInterval;
261
262 // [UE] radius multiplier for offseting path around corners
263 dtReal m_pathOffsetRadiusMultiplier;
264
265 // [UE] separation filter
266 dtReal m_separationDirFilter;
267
268 int m_maxPathResult;
269
270 int m_velocitySampleCount;
271
272 dtNavMeshQuery* m_navquery;
273
274 // [UE] if set, path visibility optimization can't leave current area type
275 bool m_raycastSingleArea;
276 // [UE] if set, offmesh connections won't be cut from corridor
277 bool m_keepOffmeshConnections;
278 // [UE] if set, crowd agents will use early reach test
279 bool m_earlyReachTest;
280
281 NAVMESH_API void updateTopologyOptimization(dtCrowdAgent** agents, const int nagents, const dtReal dt);
282 NAVMESH_API void updateMoveRequest(const dtReal dt);
283 NAVMESH_API void checkPathValidity(dtCrowdAgent** agents, const int nagents, const dtReal dt);
284
285 NAVMESH_API bool requestMoveTargetReplan(const int idx, dtPolyRef ref, const dtReal* pos);
286
287 NAVMESH_API void purge();
288
289public:
292
299
305 NAVMESH_API bool initAvoidance(const int maxNeighbors, const int maxWalls, const int maxCustomPatterns);
306
310 NAVMESH_API void setObstacleAvoidanceParams(const int idx, const dtObstacleAvoidanceParams* params);
311
317
323 NAVMESH_API void setObstacleAvoidancePattern(int idx, const dtReal* angles, const dtReal* radii, int nsamples);
324
331 NAVMESH_API bool getObstacleAvoidancePattern(int idx, dtReal* angles, dtReal* radii, int* nsamples);
332
336 NAVMESH_API const dtCrowdAgent* getAgent(const int idx);
337
340 NAVMESH_API const int getAgentCount() const;
341
347 NAVMESH_API int addAgent(const dtReal* pos, const dtCrowdAgentParams& params, const dtQueryFilter* filter);
348
352 NAVMESH_API void updateAgentParameters(const int idx, const dtCrowdAgentParams& params);
353
358 NAVMESH_API bool updateAgentFilter(const int idx, const dtQueryFilter* filter);
359
363 NAVMESH_API void updateAgentState(const int idx, bool repath);
364
367 NAVMESH_API void removeAgent(const int idx);
368
374 NAVMESH_API bool requestMoveTarget(const int idx, dtPolyRef ref, const dtReal* pos);
375
380 NAVMESH_API bool requestMoveVelocity(const int idx, const dtReal* vel);
381
385 NAVMESH_API bool resetMoveTarget(const int idx);
386
389 NAVMESH_API bool setAgentWaiting(const int idx);
390
393 NAVMESH_API bool setAgentBackOnLink(const int idx);
394
397 NAVMESH_API bool resetAgentVelocity(const int idx);
398
404
408
413
418
423
428
433
438
443
448
453
458
462
469 NAVMESH_API bool setAgentCorridor(const int idx, const dtPolyRef* path, const int npath);
470
476
481
484
486 NAVMESH_API void setPathOffsetRadiusMultiplier(dtReal RadiusMultiplier);
487
490
492 NAVMESH_API bool isOutsideCorridor(const int idx) const;
493
497 NAVMESH_API const dtQueryFilter* getFilter(const int idx) const;
498
503
506 const dtReal* getQueryExtents() const { return m_ext; }
507
510 inline int getVelocitySampleCount() const { return m_velocitySampleCount; }
511
514 const dtProximityGrid* getGrid() const { return m_grid; }
515
518 const dtPathQueue* getPathQueue() const { return &m_pathq; }
519
521 const dtNavMeshQuery* getNavMeshQuery() const { return m_navquery; }
522
524 const dtSharedBoundary* getSharedBoundary() const { return &m_sharedBoundary; }
525
527 dtCrowdAgent** getActiveAgents() const { return m_activeAgents; }
528
529 inline int getNumActiveAgents() const { return m_numActiveAgents; }
530
531 inline int getAgentIndex(const dtCrowdAgent* agent) const { return (int)(agent - m_agents); }
532
534 const dtCrowdAgentAnimation* getAgentAnims() const { return m_agentAnims; }
535};
536
541
546
547
548#endif // DETOURCROWD_H
549
551
552// This section contains detailed documentation for members that don't have
553// a source file. It reduces clutter in the main section of the header.
554
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
CrowdBoundaryFlags
Definition DetourCrowd.h:221
@ DT_CROWD_BOUNDARY_IGNORE
Definition DetourCrowd.h:222
MoveRequestState
Definition DetourCrowd.h:128
@ DT_CROWDAGENT_TARGET_WAITING_FOR_PATH
Definition DetourCrowd.h:134
@ DT_CROWDAGENT_TARGET_NONE
Definition DetourCrowd.h:129
@ DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE
Definition DetourCrowd.h:133
@ DT_CROWDAGENT_TARGET_VALID
Definition DetourCrowd.h:131
@ DT_CROWDAGENT_TARGET_REQUESTING
Definition DetourCrowd.h:132
@ DT_CROWDAGENT_TARGET_VELOCITY
Definition DetourCrowd.h:135
@ DT_CROWDAGENT_TARGET_FAILED
Definition DetourCrowd.h:130
double dtReal
Definition DetourLargeWorldCoordinates.h:15
unsigned int dtPathQueueRef
Definition DetourPathQueue.h:38
uint64 dtPolyRef
Definition RecastGraphAStar.h:28
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition DetourCrowd.h:236
const dtCrowdAgentAnimation * getAgentAnims() const
Gets all agent animations.
Definition DetourCrowd.h:534
const dtProximityGrid * getGrid() const
Definition DetourCrowd.h:514
NAVMESH_API bool initAvoidance(const int maxNeighbors, const int maxWalls, const int maxCustomPatterns)
Definition DetourCrowd.cpp:458
NAVMESH_API bool resetAgentVelocity(const int idx)
Definition DetourCrowd.cpp:796
NAVMESH_API dtCrowd()
Definition DetourCrowd.cpp:331
int getVelocitySampleCount() const
Definition DetourCrowd.h:510
const dtSharedBoundary * getSharedBoundary() const
Gets shared boundary cache.
Definition DetourCrowd.h:524
NAVMESH_API void updateAgentState(const int idx, bool repath)
Definition DetourCrowd.cpp:635
NAVMESH_API void setSeparationFilter(dtReal InFilter)
[UE] Set separation filter param
Definition DetourCrowd.cpp:1877
NAVMESH_API bool setAgentCorridor(const int idx, const dtPolyRef *path, const int npath)
Definition DetourCrowd.cpp:1847
int getNumActiveAgents() const
Definition DetourCrowd.h:529
NAVMESH_API void updateAgentParameters(const int idx, const dtCrowdAgentParams &params)
Definition DetourCrowd.cpp:522
NAVMESH_API const dtObstacleAvoidanceParams * getObstacleAvoidanceParams(const int idx) const
Definition DetourCrowd.cpp:492
NAVMESH_API void updateStepCorridor(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1666
NAVMESH_API void updateStepNextMovePoint(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1316
NAVMESH_API void updateStepPaths(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1235
NAVMESH_API void setPathOffsetRadiusMultiplier(dtReal RadiusMultiplier)
[UE] Set agent radius multiplier for offseting path from corners
Definition DetourCrowd.cpp:1882
NAVMESH_API void setAgentCheckInterval(const dtReal t)
Definition DetourCrowd.cpp:1801
NAVMESH_API void updateStepSteering(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1432
NAVMESH_API void setEarlyReachTestOptimization(bool bEnable)
[UE]
Definition DetourCrowd.cpp:1816
NAVMESH_API bool resetMoveTarget(const int idx)
Definition DetourCrowd.cpp:751
NAVMESH_API bool requestMoveTarget(const int idx, dtPolyRef ref, const dtReal *pos)
Definition DetourCrowd.cpp:712
NAVMESH_API void update(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1219
NAVMESH_API void setObstacleAvoidancePattern(int idx, const dtReal *angles, const dtReal *radii, int nsamples)
Definition DetourCrowd.cpp:499
NAVMESH_API bool requestMoveVelocity(const int idx, const dtReal *vel)
Definition DetourCrowd.cpp:734
NAVMESH_API void setPruneStartedOffmeshConnections(bool bRemoveFromCorridor)
Definition DetourCrowd.cpp:1811
NAVMESH_API void setObstacleAvoidanceParams(const int idx, const dtObstacleAvoidanceParams *params)
Definition DetourCrowd.cpp:486
NAVMESH_API ~dtCrowd()
Definition DetourCrowd.cpp:352
NAVMESH_API const dtQueryFilter * getFilter(const int idx) const
Definition DetourCrowd.cpp:1865
NAVMESH_API void updateStepOffMeshVelocity(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1739
int getAgentIndex(const dtCrowdAgent *agent) const
Definition DetourCrowd.h:531
NAVMESH_API bool init(const int maxAgents, const dtReal maxAgentRadius, dtNavMesh *nav)
Definition DetourCrowd.cpp:388
NAVMESH_API void updateStepOffMeshAnim(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1691
NAVMESH_API void setSingleAreaVisibilityOptimization(bool bEnable)
Definition DetourCrowd.cpp:1806
const dtPathQueue * getPathQueue() const
Definition DetourCrowd.h:518
NAVMESH_API void updateStepAvoidance(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1533
NAVMESH_API const int getAgentCount() const
Definition DetourCrowd.cpp:509
const dtNavMeshQuery * getNavMeshQuery() const
Gets the query object used by the crowd.
Definition DetourCrowd.h:521
NAVMESH_API bool getObstacleAvoidancePattern(int idx, dtReal *angles, dtReal *radii, int *nsamples)
Definition DetourCrowd.cpp:504
NAVMESH_API bool isOutsideCorridor(const int idx) const
[UE] Check if agent moved away from its path corridor
Definition DetourCrowd.cpp:1821
const dtReal * getQueryExtents() const
Definition DetourCrowd.h:506
dtCrowdAgent ** getActiveAgents() const
Gets all cached active agents.
Definition DetourCrowd.h:527
NAVMESH_API int cacheActiveAgents()
Definition DetourCrowd.cpp:820
NAVMESH_API dtQueryFilter * getEditableFilter(const int idx)
Definition DetourCrowd.cpp:1871
NAVMESH_API bool setAgentBackOnLink(const int idx)
Definition DetourCrowd.cpp:779
NAVMESH_API bool updateAgentFilter(const int idx, const dtQueryFilter *filter)
Definition DetourCrowd.cpp:532
NAVMESH_API int addAgent(const dtReal *pos, const dtCrowdAgentParams &params, const dtQueryFilter *filter)
Definition DetourCrowd.cpp:576
NAVMESH_API void updateStepProximityData(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1247
NAVMESH_API void removeAgent(const int idx)
Definition DetourCrowd.cpp:677
NAVMESH_API bool setAgentWaiting(const int idx)
Definition DetourCrowd.cpp:768
NAVMESH_API const dtCrowdAgent * getAgent(const int idx)
Definition DetourCrowd.cpp:517
NAVMESH_API void updateStepMove(const dtReal dt, dtCrowdAgentDebugInfo *debug)
Definition DetourCrowd.cpp:1587
Definition DetourLocalBoundary.h:34
Definition DetourNavMeshQuery.h:349
Definition DetourNavMesh.h:503
Definition DetourObstacleAvoidance.h:45
Definition DetourObstacleAvoidance.h:109
Definition DetourPathCorridor.h:36
Definition DetourPathQueue.h:41
Definition DetourProximityGrid.h:29
Definition DetourNavMeshQuery.h:96
Definition DetourSharedBoundary.h:37
NAVMESH_API dtCrowd * dtAllocCrowd()
Definition DetourCrowd.cpp:28
CrowdAgentState
Definition DetourCrowd.h:75
UpdateFlags
Definition DetourCrowd.h:208
NAVMESH_API void dtFreeCrowd(dtCrowd *ptr)
Definition DetourCrowd.cpp:35
@ DT_CROWDAGENT_STATE_OFFMESH
The agent is traversing an off-mesh connection.
Definition DetourCrowd.h:78
@ DT_CROWDAGENT_STATE_WALKING
The agent is traversing a normal navigation mesh polygon.
Definition DetourCrowd.h:77
@ DT_CROWDAGENT_STATE_INVALID
The agent is not in a valid state.
Definition DetourCrowd.h:76
@ DT_CROWDAGENT_STATE_WAITING
[UE] The agent is waiting for external movement to finish
Definition DetourCrowd.h:79
@ DT_CROWD_SEPARATION
Definition DetourCrowd.h:211
@ DT_CROWD_SLOWDOWN_AT_GOAL
[UE] Slowdown before reaching goal
Definition DetourCrowd.h:216
@ DT_CROWD_OFFSET_PATH
[UE] Offset path points from corners by agent radius
Definition DetourCrowd.h:215
@ DT_CROWD_OPTIMIZE_TOPO
Use dtPathCorridor::optimizePathTopology() to optimize the agent path.
Definition DetourCrowd.h:213
@ DT_CROWD_OPTIMIZE_VIS_MULTI
[UE] Multiple calls for optimizePathVisibility instead of checking last point
Definition DetourCrowd.h:214
@ DT_CROWD_OPTIMIZE_VIS
Use dtPathCorridor::optimizePathVisibility() to optimize the agent path.
Definition DetourCrowd.h:212
@ DT_CROWD_OBSTACLE_AVOIDANCE
Definition DetourCrowd.h:210
@ DT_CROWD_ANTICIPATE_TURNS
Definition DetourCrowd.h:209
Definition DetourCrowd.h:197
dtReal startPos[3]
Definition DetourCrowd.h:198
dtReal endPos[3]
Definition DetourCrowd.h:198
unsigned char active
Definition DetourCrowd.h:201
dtPolyRef polyRef
Definition DetourCrowd.h:199
dtReal t
Definition DetourCrowd.h:200
dtReal tmax
Definition DetourCrowd.h:200
dtReal initPos[3]
Definition DetourCrowd.h:198
Definition DetourCrowd.h:226
dtReal optStart[3]
Definition DetourCrowd.h:228
TMap< int32, FString > agentLog
Definition DetourCrowd.h:230
dtObstacleAvoidanceDebugData * vod
Definition DetourCrowd.h:229
dtReal optEnd[3]
Definition DetourCrowd.h:228
int idx
Definition DetourCrowd.h:227
Definition DetourCrowd.h:85
TSharedPtr< dtQuerySpecialLinkFilter > linkFilter
UE: special link filter used by this agent.
Definition DetourCrowd.h:90
dtReal maxAcceleration
Maximum allowed acceleration. [Limit: >= 0].
Definition DetourCrowd.h:94
void * userData
User defined data attached to the agent.
Definition DetourCrowd.h:87
dtReal maxSpeed
Maximum allowed speed. [Limit: >= 0].
Definition DetourCrowd.h:95
unsigned char filter
Definition DetourCrowd.h:124
dtReal collisionQueryRange
Defines how close a collision element must be before it is considered for steering behaviors....
Definition DetourCrowd.h:98
unsigned int groupsToIgnore
[UE] Don't avoid agents when they group is matching mask
Definition DetourCrowd.h:113
dtReal separationWeight
How aggresive the agent manager should be at avoiding collisions with this agent. [Limit: >= 0].
Definition DetourCrowd.h:103
dtReal height
Agent height. [Limit: > 0].
Definition DetourCrowd.h:93
unsigned int groupsToAvoid
[UE] Avoid agents when they group is matching mask
Definition DetourCrowd.h:111
dtReal pathOptimizationRange
The path visibility optimization range. [Limit: > 0].
Definition DetourCrowd.h:100
dtReal avoidanceQueryMultiplier
[UE] Mutliplier for avoidance velocities
Definition DetourCrowd.h:106
dtReal radius
Agent radius. [Limit: >= 0].
Definition DetourCrowd.h:92
unsigned char obstacleAvoidanceType
Definition DetourCrowd.h:120
unsigned int avoidanceGroup
[UE] Groups flags attached to the agent
Definition DetourCrowd.h:109
unsigned short updateFlags
Flags that impact steering behavior. (See: UpdateFlags)
Definition DetourCrowd.h:116
Definition DetourCrowd.h:141
unsigned char state
The type of mesh polygon the agent is traversing. (See: CrowdAgentState)
Definition DetourCrowd.h:193
unsigned char cornerFlags[DT_CROWDAGENT_MAX_CORNERS]
The local path corridor corner flags. (See: dtStraightPathFlags) [(flags) * ncorners].
Definition DetourCrowd.h:181
dtReal cornerVerts[DT_CROWDAGENT_MAX_CORNERS *3]
The local path corridor corners for the agent. (Staight path.) [(x, y, z) * ncorners].
Definition DetourCrowd.h:167
dtPolyRef targetRef
Target polyref of the movement request.
Definition DetourCrowd.h:174
dtPathQueueRef targetPathqRef
Path finder ref.
Definition DetourCrowd.h:175
unsigned char targetState
State of the movement request.
Definition DetourCrowd.h:187
int nneis
The number of neighbors.
Definition DetourCrowd.h:178
dtReal topologyOptTime
Time since the agent's path corridor was optimized.
Definition DetourCrowd.h:149
dtReal vel[3]
The actual velocity of the agent. [(x, y, z)].
Definition DetourCrowd.h:161
dtReal targetReplanTime
Definition DetourCrowd.h:172
dtReal dvel[3]
The desired velocity of the agent. [(x, y, z)].
Definition DetourCrowd.h:159
dtReal disp[3]
Definition DetourCrowd.h:158
dtPathCorridor corridor
The path corridor the agent is using.
Definition DetourCrowd.h:143
dtLocalBoundary boundary
The local boundary data for the agent.
Definition DetourCrowd.h:146
dtReal npos[3]
The current agent position. [(x, y, z)].
Definition DetourCrowd.h:157
int ncorners
The number of corners.
Definition DetourCrowd.h:184
dtReal targetPos[3]
<Time since the agent's target was replanned.
Definition DetourCrowd.h:173
dtReal desiredSpeed
The desired speed.
Definition DetourCrowd.h:155
dtCrowdNeighbour neis[DT_CROWDAGENT_MAX_NEIGHBOURS]
The known neighbors of the agent.
Definition DetourCrowd.h:152
unsigned char targetReplan
Flag indicating that the current path is being replanned.
Definition DetourCrowd.h:186
dtPolyRef cornerPolys[DT_CROWDAGENT_MAX_CORNERS]
The reference id of the polygon being entered at the corner. [(polyRef) * ncorners].
Definition DetourCrowd.h:170
unsigned char active
1 if the agent is active, or 0 if the agent is in an unused slot in the agent pool.
Definition DetourCrowd.h:190
dtReal nvel[3]
Definition DetourCrowd.h:160
dtCrowdAgentParams params
The agent's configuration parameters.
Definition DetourCrowd.h:164
Definition DetourCrowd.h:67
dtReal dist
The distance between the current agent and the neighbor.
Definition DetourCrowd.h:69
int idx
The index of the neighbor in the crowd.
Definition DetourCrowd.h:68
Definition DetourObstacleAvoidance.h:87