Path documentation

Running on all Unity licenses and platforms, Path requires no additional installs once you have it imported into your project.

The editor interface of Path is extremely simple, yet powerful:

  • One central Navigation component for general setup.
  • Add waypoints and drag them around with regular position handles.
  • One Navigator component per pathfinding agent.
  • Tweak min/max connection- and waypoint width for automatic network generation.

Runtime, Path offers a similar API:

  • Start path calculations by simply assigning the targetPosition variable.
  • Path pre-calculation.
  • Custom weights based on tagging.
  • Path invalidation.
  • Automatically form new ideal connections on scene addition load/generation.

Video material:


Access

Navigation

Description

Path system root. This class is the core of the Path system. All nodes and connections register here and the Navigator pulls data from here – as can your own code.

Functions

static Waypoint GetNearestNode (Vector3 position, Navigator navigator)
static Waypoint GetNearestNode (Vector3 position)
static void AutoScale (LayerMask layerMask, float minWidth, float maxWidth, float step)
static void AutoConnect (LayerMask layerMask, float minWidth, float maxWidth, float step)

Properties

static int SeekerIterationCap [get, set]
static ReadOnlyCollection<Waypoint> Waypoints [get]

Access

Navigator

Description

Runtime pathfinding interface. This is your runtime interface for Path. The navigator can be given a position to pathfind for, via the targetPosition variable, or you can call RequestPath in order to pre-calculate pathes.

Functions

bool DirectPath (Vector3 fromPosition, Vector3 toPosition)
bool DirectPath (Vector3 toPosition)
void ReSeek ()
void RequestPath (Vector3 startPosition, Vector3 endPosition)
void RegisterWeightHandler (string tag, WeightHandler handler)

Variables

Vector3 targetPosition = Vector3.zero
float width = 1.0f
bool selfTargetOnAwake = true
LayerMask pathBlockingLayers = 0
bool takeShortcuts = true

Sent messages

OnNewPath (Path path)
OnTargetUnreachable ()
OnPathAvailable (Path path)
OnPathUnavailable ()
OnPathInvalidated (Path path)

Path

Access

Path

Description

Pathfinding result for passing to your path follower logic.

Functions

void ArrivedAt (Waypoint waypoint)
bool Contains (Connection connection)
bool Contains (Waypoint waypoint)
void OnDrawGizmos ()
string ToString ()

Properties

Vector3 StartPosition [get]
Vector3 EndPosition [get]
Waypoint StartNode [get]
Waypoint EndNode [get]
ReadOnlyCollection<Connection> Segments [get]
float SeekTime [get, set]
Navigator Owner [get]
bool Valid [get]

Waypoint

Access

Waypoint

Description

A Path waypoint. Each waypoint is defined by a Position, a Radius and optinally a list of Connections.

Functions

void RemoveConnection (Connection connection)
void  RemoveConnection (Waypoint waypoint)
bool ConnectsTo (Waypoint waypoint)
void Disconnect ()
bool Contains (Vector3 position)
string ToString ()

Properties

ReadOnlyCollection<Connection> Connections [get]
bool Enabled [get, set]
Vector3 Position [get, set]
float Radius [get, set]
string Tag [get, set]

Connection

Access

Connection

Description

A connection between two Path nodes.

Functions

Connection (Waypoint from, Waypoint to)
string ToString ()

Properties

Waypoint From [get]
Waypoint To [get]
float Width [get, set]
string Tag [get, set]
bool Enabled [get, set]
float Cost [get]

Tutorial: Pathfinding in two lines

So you need no-nonsense pathfinding and fast? Not a problem. This brief tutorial explains how to interface with Path from your code as simple as possible.

Prerequisites:

  • The Path package has been imported into your project.
  • You’ve set up some waypoints and connected them in the editor. If you’re not sure how to do this, please check out the “Intro to Path 2.0b1” video.
  • To handle your pathfinding, you’ve created a script file and attached it to the same GameObject as your Navigator component.

Ok, here we go. Hang tight.

  1. In your MonoBehaviour script, where you want to initiate pathfinding to some point (in my case I’ve stored the point in a Vector3 variable named myDestinationPoint), add the following line: GetComponent<Navigator> ().targetPosition = myDestinationPoint;
  2. Somewhere in the same script or another script attached to the same GameObject, add the following line: public void OnNewPath (Path path) { Debug.Log ("Path: " + path); }
  3. Put on a nice tune and make a kick-ass game!