Roblox UtilitiesDevlHub Roblox Documentation

Class

Path

NotCreatableNotReplicated
Inherits
Instance › Object
Memory category
Instances

Stores the result of paths created by PathfindingService:CreatePath().

Path objects store the result of paths created by PathfindingService:CreatePath().

Once a Path object is created, you can call ComputeAsync() with a starting point and ending point. This will attempt to compute a valid path for a character to move along, based on default or custom parameters passed to CreatePath(). If ComputeAsync() successfully finds a path, the Path object will have a Status value of PathStatus.Success. Otherwise the status will be PathStatus.NoPath which can occur if there are obstacles between the two points (and no way around) or if the points are inside of solid objects.

In addition to ComputeAsync(), Path objects have the GetWaypoints() method which returns a list of waypoints representing the points a character should follow in sequence to get from the beginning to the end of the path.

Finally, Path objects can be connected to the Blocked event which will fire if, at any time during the path's existence, the path is blocked. Note that this can occur behind a character moving along the path, not just in front of it.

See Pathfinding for details on implementing character pathfinding.

Properties 1#

StatusPathStatusThe PathStatus of the generated Path.ReadSafeReadOnlyNotReplicated

Status: PathStatus#

ReadOnlyNotReplicatedReadSafe

The PathStatus of the generated Path.

Methods 4#

CheckOcclusionAsyncChecks if a path is blocked starting at a specific waypoint.DeprecatedYields
ComputeAsyncComputes a Path from a start position to an end position.Yields
GetPointCoordinatesReturns a table of Path instances.Deprecated
GetWaypointsReturns an array of points in the path.

CheckOcclusionAsync(start: int): int#

YieldsDeprecated

Deprecated. This function has been superseded by the Blocked event which you can connect to a Path object and should be used instead. This lets you detect if the path becomes blocked at any time during its existence.

This function checks if a path is blocked starting at the waypoint indicated by start.

It returns the first waypoint of occlusion if blocked, -1 if not. it returns an error if start is less than 0 or greater than the number of waypoints in the Path.

NameTypeDefaultDescription
startintThe 1-based index of the waypoint from which to begin checking for occlusion.
Returns
  • int — The 1-based index of the first blocked waypoint starting from start, or -1 if the path is not blocked.

ComputeAsync(start: Vector3, finish: Vector3): ()#

Yields

This function computes a Path from a start position to an end position. This function is not automatically called when a path is created and must be invoked each time the path needs to be updated.

Once the path is computed, it will have a series of waypoints that, when followed, can lead a character along the path. These points are gathered with the GetWaypoints() function.

NameTypeDefaultDescription
startVector3The world position where the computed path begins.
finishVector3The world position where the computed path finishes.
Returns
  • ()

GetPointCoordinates(): Array#

DeprecatedDeprecated

Deprecated. This item has been superseded by GetWaypoints() which should be used in all new work instead.

This function returns a table of Path instances.

Returns
  • Array — An array of Vector3 positions for each waypoint in the path.

GetWaypoints(): Array#

This method returns an array of all the PathWaypoints in a Path as computed by ComputeAsync().

Each waypoint in the array specifies a Vector3 position and PathWaypointAction to take when the waypoint is reached. The array is arranged in the order of waypoints from the path start to path end.

If a path could not be computed, this function will return an empty array.

Returns
  • Array — An array of PathWaypoints ordered from path start to path end.

Events 2#

BlockedFires when the computed path becomes blocked.
UnblockedFires when a computed path that was blocked becomes unblocked.

Blocked(blockedWaypointIdx: int)#

Fires when the computed path becomes blocked. Note that paths may become blocked somewhere behind the agent, such as a pile of rubble falling on a path as the agent runs away. See blocked paths for details on checking the forward waypoint progress of an agent along a path.

NameTypeDefaultDescription
blockedWaypointIdxintThe 1-based index of the waypoint at which the path became blocked.

Unblocked(unblockedWaypointIdx: int)#

Fires when a computed path that was blocked becomes unblocked. Note that a blocked path may become unblocked somewhere behind the agent, effectively making reaction to this event unnecessary. See blocked paths for details on checking the forward waypoint progress of an agent along a path.

NameTypeDefaultDescription
unblockedWaypointIdxintThe 1-based index of the waypoint at which the path became unblocked.

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed