UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
dtCrowd Class Reference

#include <DetourCrowd.h>

Public Member Functions

NAVMESH_API dtCrowd ()
 
NAVMESH_API ~dtCrowd ()
 
NAVMESH_API bool init (const int maxAgents, const dtReal maxAgentRadius, dtNavMesh *nav)
 
NAVMESH_API bool initAvoidance (const int maxNeighbors, const int maxWalls, const int maxCustomPatterns)
 
NAVMESH_API void setObstacleAvoidanceParams (const int idx, const dtObstacleAvoidanceParams *params)
 
NAVMESH_API const dtObstacleAvoidanceParamsgetObstacleAvoidanceParams (const int idx) const
 
NAVMESH_API void setObstacleAvoidancePattern (int idx, const dtReal *angles, const dtReal *radii, int nsamples)
 
NAVMESH_API bool getObstacleAvoidancePattern (int idx, dtReal *angles, dtReal *radii, int *nsamples)
 
NAVMESH_API const dtCrowdAgentgetAgent (const int idx)
 
NAVMESH_API const int getAgentCount () const
 
NAVMESH_API int addAgent (const dtReal *pos, const dtCrowdAgentParams &params, const dtQueryFilter *filter)
 
NAVMESH_API void updateAgentParameters (const int idx, const dtCrowdAgentParams &params)
 
NAVMESH_API bool updateAgentFilter (const int idx, const dtQueryFilter *filter)
 
NAVMESH_API void updateAgentState (const int idx, bool repath)
 
NAVMESH_API void removeAgent (const int idx)
 
NAVMESH_API bool requestMoveTarget (const int idx, dtPolyRef ref, const dtReal *pos)
 
NAVMESH_API bool requestMoveVelocity (const int idx, const dtReal *vel)
 
NAVMESH_API bool resetMoveTarget (const int idx)
 
NAVMESH_API bool setAgentWaiting (const int idx)
 
NAVMESH_API bool setAgentBackOnLink (const int idx)
 
NAVMESH_API bool resetAgentVelocity (const int idx)
 
NAVMESH_API int getActiveAgents (dtCrowdAgent **agents, const int maxAgents)
 
NAVMESH_API int cacheActiveAgents ()
 
NAVMESH_API void update (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void updateStepPaths (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void updateStepProximityData (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void updateStepNextMovePoint (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void updateStepSteering (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void updateStepAvoidance (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void updateStepMove (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void updateStepCorridor (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void updateStepOffMeshAnim (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void updateStepOffMeshVelocity (const dtReal dt, dtCrowdAgentDebugInfo *debug)
 
NAVMESH_API void setAgentCheckInterval (const dtReal t)
 
NAVMESH_API bool setAgentCorridor (const int idx, const dtPolyRef *path, const int npath)
 
NAVMESH_API void setSingleAreaVisibilityOptimization (bool bEnable)
 
NAVMESH_API void setPruneStartedOffmeshConnections (bool bRemoveFromCorridor)
 
NAVMESH_API void setEarlyReachTestOptimization (bool bEnable)
 [UE]
 
NAVMESH_API void setPathOffsetRadiusMultiplier (dtReal RadiusMultiplier)
 [UE] Set agent radius multiplier for offseting path from corners
 
NAVMESH_API void setSeparationFilter (dtReal InFilter)
 [UE] Set separation filter param
 
NAVMESH_API bool isOutsideCorridor (const int idx) const
 [UE] Check if agent moved away from its path corridor
 
NAVMESH_API const dtQueryFiltergetFilter (const int idx) const
 
NAVMESH_API dtQueryFiltergetEditableFilter (const int idx)
 
const dtRealgetQueryExtents () const
 
int getVelocitySampleCount () const
 
const dtProximityGridgetGrid () const
 
const dtPathQueuegetPathQueue () const
 
const dtNavMeshQuerygetNavMeshQuery () const
 Gets the query object used by the crowd.
 
const dtSharedBoundarygetSharedBoundary () const
 Gets shared boundary cache.
 
dtCrowdAgent ** getActiveAgents () const
 Gets all cached active agents.
 
int getNumActiveAgents () const
 
int getAgentIndex (const dtCrowdAgent *agent) const
 
const dtCrowdAgentAnimationgetAgentAnims () const
 Gets all agent animations.
 

Detailed Description

Provides local steering behaviors for a group of agents.

This is the core class of the Crowd module. See the Crowd documentation for a summary of the crowd features.

A common method for setting up the crowd is as follows:

  1. Allocate the crowd using dtAllocCrowd.
  2. Initialize the crowd using init().
  3. Set the avoidance configurations using setObstacleAvoidanceParams().
  4. Add agents using addAgent() and make an initial movement request using requestMoveTarget().

A common process for managing the crowd is as follows:

  1. Call update() to allow the crowd to manage its agents.
  2. Retrieve agent information using getActiveAgents().
  3. Make movement requests using requestMoveTarget() when movement goal changes.
  4. Repeat every frame.

Some agent configuration settings can be updated using updateAgentParameters(). But the crowd owns the agent position. So it is not possible to update an active agent's position. If agent position must be fed back into the crowd, the agent must be removed and re-added.

Notes:

  • Path related information is available for newly added agents only after an update() has been performed.
  • Agent objects are kept in a pool and re-used. So it is important when using agent objects to check the value of dtCrowdAgent::active to determine if the agent is actually in use or not.
  • This class is meant to provide 'local' movement. There is a limit of 256 polygons in the path corridor.
    So it is not meant to provide automatic pathfinding services over long distances.
See also
dtAllocCrowd(), dtFreeCrowd(), init(), dtCrowdAgent

Constructor & Destructor Documentation

◆ dtCrowd()

dtCrowd::dtCrowd ( )

◆ ~dtCrowd()

dtCrowd::~dtCrowd ( )

Member Function Documentation

◆ addAgent()

int dtCrowd::addAgent ( const dtReal pos,
const dtCrowdAgentParams params,
const dtQueryFilter filter 
)

Adds a new agent to the crowd.

Parameters
[in]posThe requested position of the agent. [(x, y, z)]
[in]paramsThe configutation of the agent.
[in]filter[UE] query filter used by agent
Returns
The index of the agent in the agent pool. Or -1 if the agent could not be added.

The agent's position will be constrained to the surface of the navigation mesh.

◆ cacheActiveAgents()

int dtCrowd::cacheActiveAgents ( )

Cache list of active agents

Returns
The number of active agents

◆ getActiveAgents() [1/2]

dtCrowdAgent ** dtCrowd::getActiveAgents ( ) const
inline

Gets all cached active agents.

◆ getActiveAgents() [2/2]

int dtCrowd::getActiveAgents ( dtCrowdAgent **  agents,
const int  maxAgents 
)

Gets the active agents int the agent pool.

Parameters
[out]agentsAn array of agent pointers. [(dtCrowdAgent *) * maxAgents]
[in]maxAgentsThe size of the crowd agent array.
Returns
The number of agents returned in agents.

◆ getAgent()

const dtCrowdAgent * dtCrowd::getAgent ( const int  idx)

Gets the specified agent from the pool.

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]
Returns
The requested agent.

agents in the pool may not be in use. Check dtCrowdAgent.active before using the returned object.

◆ getAgentAnims()

const dtCrowdAgentAnimation * dtCrowd::getAgentAnims ( ) const
inline

Gets all agent animations.

◆ getAgentCount()

const int dtCrowd::getAgentCount ( ) const

The maximum number of agents that can be managed by the object.

Returns
The maximum number of agents.

◆ getAgentIndex()

int dtCrowd::getAgentIndex ( const dtCrowdAgent agent) const
inline

◆ getEditableFilter()

dtQueryFilter * dtCrowd::getEditableFilter ( const int  idx)

Gets the filter used by the crowd.

Parameters
[in]idx[UE] The agent index. [Limits: 0 <= value < getAgentCount()]
Returns
The filter used by the crowd.

◆ getFilter()

const dtQueryFilter * dtCrowd::getFilter ( const int  idx) const

Gets the filter used by the crowd.

Parameters
[in]idx[UE] The agent index. [Limits: 0 <= value < getAgentCount()]
Returns
The filter used by the crowd.

◆ getGrid()

const dtProximityGrid * dtCrowd::getGrid ( ) const
inline

Gets the crowd's proximity grid.

Returns
The crowd's proximity grid.

◆ getNavMeshQuery()

const dtNavMeshQuery * dtCrowd::getNavMeshQuery ( ) const
inline

Gets the query object used by the crowd.

◆ getNumActiveAgents()

int dtCrowd::getNumActiveAgents ( ) const
inline

◆ getObstacleAvoidanceParams()

const dtObstacleAvoidanceParams * dtCrowd::getObstacleAvoidanceParams ( const int  idx) const

Gets the shared avoidance configuration for the specified index.

Parameters
[in]idxThe index of the configuration to retreive. [Limits: 0 <= value < DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS]
Returns
The requested configuration.

◆ getObstacleAvoidancePattern()

bool dtCrowd::getObstacleAvoidancePattern ( int  idx,
dtReal angles,
dtReal radii,
int *  nsamples 
)

[UE] Gets the shared avoidance sampling pattern for the specified index.

Parameters
[in]idxThe index.
[in]anglesradians from direction of desired velocity [Count: nsamples]
[in]radiinormalized radii (0..1) for each sample [Count: nsamples]
[in]nsamplesThe number of samples
Returns
true if pattern was found

◆ getPathQueue()

const dtPathQueue * dtCrowd::getPathQueue ( ) const
inline

Gets the crowd's path request queue.

Returns
The crowd's path request queue.

◆ getQueryExtents()

const dtReal * dtCrowd::getQueryExtents ( ) const
inline

Gets the search extents [(x, y, z)] used by the crowd for query operations.

Returns
The search extents used by the crowd. [(x, y, z)]

◆ getSharedBoundary()

const dtSharedBoundary * dtCrowd::getSharedBoundary ( ) const
inline

Gets shared boundary cache.

◆ getVelocitySampleCount()

int dtCrowd::getVelocitySampleCount ( ) const
inline

Gets the velocity sample count.

Returns
The velocity sample count.

◆ init()

bool dtCrowd::init ( const int  maxAgents,
const dtReal  maxAgentRadius,
dtNavMesh nav 
)

Initializes the crowd.

Parameters
[in]maxAgentsThe maximum number of agents the crowd can manage. [Limit: >= 1]
[in]maxAgentRadiusThe maximum radius of any agent that will be added to the crowd. [Limit: > 0]
[in]navThe navigation mesh to use for planning.
Returns
True if the initialization succeeded.

May be called more than once to purge and re-initialize the crowd.

◆ initAvoidance()

bool dtCrowd::initAvoidance ( const int  maxNeighbors,
const int  maxWalls,
const int  maxCustomPatterns 
)

[UE] Initializes the avoidance query.

Parameters
[in]maxNeighborsThe maximum number of processed neighbors
[in]maxWallsThe maximum number of processed wall segments
[in]maxCustomPatternsThe maximum number of custom sampling patterns
Returns
True if the initialization succeeded.

◆ isOutsideCorridor()

bool dtCrowd::isOutsideCorridor ( const int  idx) const

[UE] Check if agent moved away from its path corridor

◆ removeAgent()

void dtCrowd::removeAgent ( const int  idx)

Removes the agent from the crowd.

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]

The agent is deactivated and will no longer be processed. Its dtCrowdAgent object is not removed from the pool. It is marked as inactive so that it is available for reuse.

◆ requestMoveTarget()

bool dtCrowd::requestMoveTarget ( const int  idx,
dtPolyRef  ref,
const dtReal pos 
)

Submits a new move request for the specified agent.

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]
[in]refThe position's polygon reference.
[in]posThe position within the polygon. [(x, y, z)]
Returns
True if the request was successfully submitted.

This method is used when a new target is set.

The position will be constrained to the surface of the navigation mesh.

The request will be processed during the next update().

◆ requestMoveVelocity()

bool dtCrowd::requestMoveVelocity ( const int  idx,
const dtReal vel 
)

Submits a new move request for the specified agent.

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]
[in]velThe movement velocity. [(x, y, z)]
Returns
True if the request was successfully submitted.

◆ resetAgentVelocity()

bool dtCrowd::resetAgentVelocity ( const int  idx)

[UE] Resets agent's velocity

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]

◆ resetMoveTarget()

bool dtCrowd::resetMoveTarget ( const int  idx)

Resets any request for the specified agent.

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]
Returns
True if the request was successfully reseted.

◆ setAgentBackOnLink()

bool dtCrowd::setAgentBackOnLink ( const int  idx)

[UE] Switch to offmesh link state

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]

◆ setAgentCheckInterval()

void dtCrowd::setAgentCheckInterval ( const dtReal  t)

[UE] Set time between attempts to restore agents state

Parameters
[in]tTime in seconds

◆ setAgentCorridor()

bool dtCrowd::setAgentCorridor ( const int  idx,
const dtPolyRef path,
const int  npath 
)

[UE] Set agent corridor, works only just after requesting move target when agent didn't start any pathfinding operations yet Use with caution!

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]
[in]pathThe path corridor. [(polyRef) * npolys]
[in]npathThe number of polygons in the path.

◆ setAgentWaiting()

bool dtCrowd::setAgentWaiting ( const int  idx)

[UE] Switch to waiting state

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]

◆ setEarlyReachTestOptimization()

void dtCrowd::setEarlyReachTestOptimization ( bool  bEnable)

[UE]

◆ setObstacleAvoidanceParams()

void dtCrowd::setObstacleAvoidanceParams ( const int  idx,
const dtObstacleAvoidanceParams params 
)

Sets the shared avoidance configuration for the specified index.

Parameters
[in]idxThe index. [Limits: 0 <= value < DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS]
[in]paramsThe new configuration.

◆ setObstacleAvoidancePattern()

void dtCrowd::setObstacleAvoidancePattern ( int  idx,
const dtReal angles,
const dtReal radii,
int  nsamples 
)

[UE] Sets the shared avoidance sampling pattern for the specified index.

Parameters
[in]idxThe index.
[in]anglesradians from direction of desired velocity [Count: nsamples]
[in]radiinormalized radii (0..1) for each sample [Count: nsamples]
[in]nsamplesThe number of samples

◆ setPathOffsetRadiusMultiplier()

void dtCrowd::setPathOffsetRadiusMultiplier ( dtReal  RadiusMultiplier)

[UE] Set agent radius multiplier for offseting path from corners

◆ setPruneStartedOffmeshConnections()

void dtCrowd::setPruneStartedOffmeshConnections ( bool  bRemoveFromCorridor)

[UE] Set offmesh connection pruning This will allow removing offmesh connection poly ref from corridor as soon as offmesh connection anim is triggered (default behavior)

◆ setSeparationFilter()

void dtCrowd::setSeparationFilter ( dtReal  InFilter)

[UE] Set separation filter param

◆ setSingleAreaVisibilityOptimization()

void dtCrowd::setSingleAreaVisibilityOptimization ( bool  bEnable)

[UE] Set visibility optimization to use single area raycasts This will prevent from cutting through polys marked as different area which could have been avoided in corridor's path

Parameters
[in]bEnableNew state of single area raycast mode

◆ update()

void dtCrowd::update ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

Updates the steering and positions of all agents.

Parameters
[in]dtThe time, in seconds, to update the simulation. [Limit: > 0]
[out]debugA debug object to load with debug information. [Opt]

◆ updateAgentFilter()

bool dtCrowd::updateAgentFilter ( const int  idx,
const dtQueryFilter filter 
)

[UE] Updates the specified agent's query filter.

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]
[in]filterThe new filter.
Returns
True if the request was successfully submitted.

◆ updateAgentParameters()

void dtCrowd::updateAgentParameters ( const int  idx,
const dtCrowdAgentParams params 
)

Updates the specified agent's configuration.

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]
[in]paramsThe new agent configuration.

◆ updateAgentState()

void dtCrowd::updateAgentState ( const int  idx,
bool  repath 
)

[UE] Refresh state of agent, used after completing movement through offmesh links

Parameters
[in]idxThe agent index. [Limits: 0 <= value < getAgentCount()]
[in]repathIf set, agent will invalidate its path

◆ updateStepAvoidance()

void dtCrowd::updateStepAvoidance ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

[UE] Split update into several smaller components: avoidance

Parameters
[in]dtDelta time in seconds
[in]nagentsNumber of active agents

◆ updateStepCorridor()

void dtCrowd::updateStepCorridor ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

[UE] Split update into several smaller components: corridor updates at new position

Parameters
[in]dtDelta time in seconds
[in]nagentsNumber of active agents

◆ updateStepMove()

void dtCrowd::updateStepMove ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

[UE] Split update into several smaller components: integrate velocities and handle collisions

Parameters
[in]dtDelta time in seconds
[in]nagentsNumber of active agents

◆ updateStepNextMovePoint()

void dtCrowd::updateStepNextMovePoint ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

[UE] Split update into several smaller components: next corner for move, trigger offmesh links

Parameters
[in]dtDelta time in seconds
[in]nagentsNumber of active agents

◆ updateStepOffMeshAnim()

void dtCrowd::updateStepOffMeshAnim ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

[UE] Split update into several smaller components: offmesh anims

Parameters
[in]dtDelta time in seconds
[in]nagentsNumber of active agents

◆ updateStepOffMeshVelocity()

void dtCrowd::updateStepOffMeshVelocity ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

[UE] Split update into several smaller components: offmesh link velocity (instead of playing animation)

Parameters
[in]dtDelta time in seconds
[in]nagentsNumber of active agents

◆ updateStepPaths()

void dtCrowd::updateStepPaths ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

[UE] Split update into several smaller components: path validity, path cache and path optimizations

Parameters
[in]dtDelta time in seconds
[in]nagentsNumber of active agents

◆ updateStepProximityData()

void dtCrowd::updateStepProximityData ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

[UE] Split update into several smaller components: neighbors and boundaries

Parameters
[in]dtDelta time in seconds
[in]nagentsNumber of active agents

◆ updateStepSteering()

void dtCrowd::updateStepSteering ( const dtReal  dt,
dtCrowdAgentDebugInfo debug 
)

[UE] Split update into several smaller components: steering

Parameters
[in]dtDelta time in seconds
[in]nagentsNumber of active agents

The documentation for this class was generated from the following files: