A* Pathfinding Project  3.1.4
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Enumerations Properties Groups Pages
NavGraph Class Referenceabstract

Base class for all graphs More...

+ Inheritance diagram for NavGraph:
+ Collaboration diagram for NavGraph:

Public Member Functions

virtual void Awake ()
 This will be called on the same time as Awake on the gameObject which the AstarPath script is attached to.
 
virtual Node[] CreateNodes (int number)
 Creates a number of nodes with the correct type for the graph.
 
virtual void DeserializeExtraInfo (byte[] bytes)
 Deserializes graph type specific node data.
 
NNInfo GetNearest (Vector3 position)
 Returns the nearest node to a position using the default NNConstraint.
 
NNInfo GetNearest (Vector3 position, NNConstraint constraint)
 Returns the nearest node to a position using the specified NNConstraint.
 
virtual NNInfo GetNearest (Vector3 position, NNConstraint constraint, Node hint)
 Returns the nearest node to a position using the specified NNConstraint.
 
virtual NNInfo GetNearestForce (Vector3 position, NNConstraint constraint)
 Returns the nearest node to a position using the specified constraint.
 
bool InSearchTree (Node node, Path path)
 Returns if the node is in the search tree of the path.
 
virtual Color NodeColor (Node node, NodeRunData data)
 
virtual void OnDestroy ()
 Function for cleaning up references.
 
virtual void OnDrawGizmos (bool drawNodes)
 
virtual void PostDeserialization ()
 Called after all deserialization has been done for all graphs.
 
virtual void RelocateNodes (Matrix4x4 oldMatrix, Matrix4x4 newMatrix)
 Relocates the nodes in this graph.
 
void SafeOnDestroy ()
 SafeOnDestroy should be used when there is a risk that the pathfinding is searching through this graph when called
 
abstract void Scan ()
 Scans the graph, called from AstarPath.Scan Override this function to implement custom scanning logic
 
void ScanGraph ()
 Consider using AstarPath.Scan () instead since this function might screw things up if there is more than one graph.
 
virtual byte[] SerializeExtraInfo ()
 Serializes graph type specific node data.
 

Public Attributes

byte[] _sguid
 Used to store the guid value.
 
AstarPath active
 Reference to the AstarPath object in the scene.
 
bool drawGizmos = true
 
bool infoScreenOpen
 Used in the editor to check if the info screen is open.
 
uint initialPenalty = 0
 
Matrix4x4 matrix
 A matrix for translating/rotating/scaling the graph.
 
string name
 
Node[] nodes
 All nodes this graph contains.
 
bool open
 Is the graph open in the editor
 

Properties

Guid guid [get, set]
 Used as an ID of the graph, considered to be unique.
 
Matrix4x4 inverseMatrix [get]
 

Detailed Description

Base class for all graphs

Member Function Documentation

virtual void Awake ( )
virtual

This will be called on the same time as Awake on the gameObject which the AstarPath script is attached to.

(remember, not in the editor) Use this for any initialization code which can't be placed in Scan

+ Here is the caller graph for this function:

virtual Node [] CreateNodes ( int  number)
virtual

Creates a number of nodes with the correct type for the graph.

This should not set the nodes array, only return the nodes. Called by graph generators and when deserializing a graph with nodes. Override this function if you do not use the default Pathfinding::Node class.

Reimplemented in GridGraph, RecastGraph, NavMeshGraph, LayerGridGraph, and CustomGridGraph.

+ Here is the caller graph for this function:

virtual void DeserializeExtraInfo ( byte[]  bytes)
virtual

Deserializes graph type specific node data.

See Also
SerializeExtraInfo

Reimplemented in NavMeshGraph, and RecastGraph.

NNInfo GetNearest ( Vector3  position)

Returns the nearest node to a position using the default NNConstraint.

Parameters
positionThe position to try to find a close node to
See Also
Pathfinding.NNConstraint.None

+ Here is the caller graph for this function:

NNInfo GetNearest ( Vector3  position,
NNConstraint  constraint 
)

Returns the nearest node to a position using the specified NNConstraint.

Parameters
positionThe position to try to find a close node to
constraintCan for example tell the function to try to return a walkable node. If you do not get a good node back, consider calling GetNearestForce.

+ Here is the call graph for this function:

virtual NNInfo GetNearest ( Vector3  position,
NNConstraint  constraint,
Node  hint 
)
virtual

Returns the nearest node to a position using the specified NNConstraint.

Parameters
positionThe position to try to find a close node to
hintCan be passed to enable some graph generators to find the nearest node faster.
constraintCan for example tell the function to try to return a walkable node. If you do not get a good node back, consider calling GetNearestForce.

Reimplemented in LayerGridGraph, GridGraph, RecastGraph, NavMeshGraph, and MultiGridGraph.

+ Here is the call graph for this function:

virtual NNInfo GetNearestForce ( Vector3  position,
NNConstraint  constraint 
)
virtual

Returns the nearest node to a position using the specified constraint.

Parameters
positionA Vector3
constraintA NNConstraint
Returns
A NNInfo. This function will only return an empty NNInfo if there is no nodes which comply with the specified constraint.

Reimplemented in LayerGridGraph, GridGraph, RecastGraph, and NavMeshGraph.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool InSearchTree ( Node  node,
Path  path 
)

Returns if the node is in the search tree of the path.

Only guaranteed to be correct if path is the latest path calculated. Use for gizmo drawing only.

+ Here is the call graph for this function:

virtual void OnDestroy ( )
virtual

Function for cleaning up references.

This will be called on the same time as OnDisable on the gameObject which the AstarPath script is attached to (remember, not in the editor) Use for any cleanup code such as cleaning up static variables which otherwise might prevent resources from being collected Use by creating a function overriding this one in a graph class, but always call base.OnDestroy () in that function.

Reimplemented in GridGraph, and LayerGridGraph.

+ Here is the caller graph for this function:

virtual void PostDeserialization ( )
virtual

Called after all deserialization has been done for all graphs.

Can be used to set up more graph data which is not serialized

Reimplemented in GridGraph.

virtual void RelocateNodes ( Matrix4x4  oldMatrix,
Matrix4x4  newMatrix 
)
virtual

Relocates the nodes in this graph.

Assumes the nodes are translated using the "oldMatrix", then translates them according to the "newMatrix". The "oldMatrix" is not required by all implementations of this function though (e.g the NavMesh generator).

Bug:
Does not always work for Grid Graphs, see http://www.arongranberg.com/forums/topic/relocate-nodes-fix/

Reimplemented in NavMeshGraph.

void SafeOnDestroy ( )

SafeOnDestroy should be used when there is a risk that the pathfinding is searching through this graph when called

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

abstract void Scan ( )
pure virtual

Scans the graph, called from AstarPath.Scan Override this function to implement custom scanning logic

Implemented in NavMeshGraph, GridGraph, LayerGridGraph, RecastGraph, MultiGridGraph, PointGraph, and SimpleGraph.

+ Here is the caller graph for this function:

void ScanGraph ( )

Consider using AstarPath.Scan () instead since this function might screw things up if there is more than one graph.

This function does not perform all necessary postprocessing for the graph to work with pathfinding (e.g flood fill). See the source of the AstarPath.Scan function to see how it can be used.

In almost all cases you should use AstarPath.Scan instead.

+ Here is the call graph for this function:

virtual byte [] SerializeExtraInfo ( )
virtual

Serializes graph type specific node data.

This function can be overriden to serialize extra node information (or graph information for that matter) which cannot be serialized using the standard serialization. Serialize the data in any way you want and return a byte array. When loading, the exact same byte array will be passed to the DeserializeExtraInfo function.
These functions will only be called if node serialization is enabled.
If null is returned from this function, the DeserializeExtraInfo function will not be called on load.

Reimplemented in NavMeshGraph, and RecastGraph.

Member Data Documentation

byte [] _sguid

Used to store the guid value.

See Also
NavGraph::guid
AstarPath active

Reference to the AstarPath object in the scene.

Might not be entirely safe to use, it's better to use AstarPath.active

bool infoScreenOpen

Used in the editor to check if the info screen is open.

Should be inside UNITY_EDITOR only #ifs but just in case anyone tries to serialize a NavGraph instance using Unity, I have left it like this as it would otherwise cause a crash when building. Version 3.0.8.1 was released because of this bug only

Matrix4x4 matrix

A matrix for translating/rotating/scaling the graph.

Not all graph generators sets this variable though.

Node [] nodes

All nodes this graph contains.

This can be iterated to search for a specific node. This should be set if the graph does contain any nodes.

Note
Entries are permitted to be NULL, make sure you account for that when iterating a graph's nodes
bool open

Is the graph open in the editor

Property Documentation

Guid guid
getset

Used as an ID of the graph, considered to be unique.

Note
This is Pathfinding.Util.Guid not System.Guid. A replacement for System.Guid was coded for better compatibility with iOS

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