A* Pathfinding Project  3.6.1
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
GridGraph Class Reference

Generates a grid of nodes. More...

Detailed Description

Generates a grid of nodes.

The GridGraph does exactly what the name implies, generates nodes in a grid pattern.
Grid graphs suit well to when you already have a grid based world. Features:

  • You can update the graph during runtime (good for e.g Tower Defence or RTS games)
  • Throw any scene at it, with minimal configurations you can get a good graph from it.
  • Supports raycast and the funnel algorithm
  • Predictable pattern
  • Can apply penalty and walkability values from a supplied image
  • Perfect for terrain worlds since it can make areas unwalkable depending on the slope

The The Snap Size button snaps the internal size of the graph to exactly contain the current number of nodes, i.e not contain 100.3 nodes but exactly 100 nodes.
This will make the "center" coordinate more accurate.

Updating the graph during runtime Any graph which implements the IUpdatableGraph interface can be updated during runtime.
For grid graphs this is a great feature since you can update only a small part of the grid without causing any lag like a complete rescan would.
If you for example just have instantiated a sphere obstacle in the scene and you want to update the grid where that sphere was instantiated, you can do this:

AstarPath.active.UpdateGraphs (ob.collider.bounds);

Where ob is the obstacle you just instantiated (a GameObject).
As you can see, the UpdateGraphs function takes a Bounds parameter and it will send an update call to all updateable graphs.
A grid graph will update that area and a small margin around it equal to collision testing diameter/2

See Also
graph-updates for more info about updating Graph Types during runtime

Hexagon graphs The graph can be configured to work like a hexagon graph with some simple settings. Just set the neighbours (called 'connections' in the editor) field to 'Six' and then click the 'Configure as Hexagon Graph' button that will show up. That will set the isometricAngle field to 54.74 (more precisely 90-atan(1/sqrt(2))) and enable uniformEdgeCosts.

Then the graph will work like a hexagon graph. You might want to rotate it to better match your game however.

Note however that the snapping to the closest node is not exactly as you would expect in a real hexagon graph, but it is close enough that you will likely not notice.

Configure using code

// This holds all graph data
AstarData data = AstarPath.active.astarData;
// This creates a Grid Graph
GridGraph gg = data.AddGraph(typeof(GridGraph)) as GridGraph;
// Setup a grid graph with some values
gg.width = 50;
gg.depth = 50;
gg.nodeSize = 1;
gg.center = new Vector3 (10,0,0);
// Updates internal size from the above values
gg.UpdateSizeFromWidthDepth();
// Scans all graphs, do not call gg.Scan(), that is an internal method

Classes

class  TextureData
 Used for using a texture as a source for a grid graph. More...
 

Public Member Functions

 GridGraph ()
 
virtual void CalculateConnections (GridNode[] nodes, int x, int z, GridNode node)
 Calculates the grid connections for a single node.
 
GraphUpdateThreading CanUpdateAsync (GraphUpdateObject o)
 
bool CheckConnection (GridNode node, int dir)
 Returns if node is connected to it's neighbour in the specified direction.
 
override void DeserializeExtraInfo (GraphSerializationContext ctx)
 Deserializes graph type specific node data.
 
virtual void ErodeWalkableArea ()
 Erodes the walkable area.
 
virtual void ErodeWalkableArea (int xmin, int zmin, int xmax, int zmax)
 Erodes the walkable area.
 
void GenerateMatrix ()
 Generates the matrix used for translating nodes from grid coordinates to world coordintes.
 
uint GetConnectionCost (int dir)
 
override NNInfo GetNearest (Vector3 position, NNConstraint constraint, GraphNode hint)
 
override NNInfo GetNearestForce (Vector3 position, NNConstraint constraint)
 
GridNode GetNodeConnection (GridNode node, int dir)
 
Int3 GetNodePosition (int index, int yOffset)
 
override void GetNodes (GraphNodeDelegateCancelable del)
 Calls a delegate with all nodes in the graph.
 
List< GraphNodeGetNodesInArea (Bounds b)
 All nodes inside the bounding box.
 
List< GraphNodeGetNodesInArea (GraphUpdateShape shape)
 All nodes inside the shape.
 
bool HasNodeConnection (GridNode node, int dir)
 
bool HasNodeConnection (int index, int x, int z, int dir)
 
virtual bool IsValidConnection (GridNode n1, GridNode n2)
 Returns true if a connection between the adjacent nodes n1 and n2 is valid.
 
bool Linecast (Vector3 _a, Vector3 _b)
 Returns if there is an obstacle between origin and end on the graph.
 
bool Linecast (Vector3 _a, Vector3 _b, GraphNode hint)
 Returns if there is an obstacle between origin and end on the graph.
 
bool Linecast (Vector3 _a, Vector3 _b, GraphNode hint, out GraphHitInfo hit)
 Returns if there is an obstacle between origin and end on the graph.
 
bool Linecast (Vector3 _a, Vector3 _b, GraphNode hint, out GraphHitInfo hit, List< GraphNode > trace)
 Returns if there is an obstacle between origin and end on the graph.
 
override void OnDestroy ()
 This function will be called when this graph is destroyed.
 
override void OnDrawGizmos (bool drawNodes)
 Draw gizmos for the graph.
 
void OnPostScan (AstarPath script)
 Auto links grid graphs together.
 
override void PostDeserialization ()
 Called after all deserialization has been done for all graphs.
 
void RelocateNodes (Vector3 center, Quaternion rotation, float nodeSize, float aspectRatio=1, float isometricAngle=0)
 Relocate the grid graph using new settings.
 
override void ScanInternal (OnScanStatus statusCallback)
 Scans the graph, called from AstarPath.ScanInternal Override this function to implement custom scanning logic The statusCallback may be optionally called to show progress info in the editor
 
override void SerializeExtraInfo (GraphSerializationContext ctx)
 Serializes graph type specific node data.
 
void SetNodeConnection (GridNode node, int dir, bool value)
 
void SetNodeConnection (int index, int x, int z, int dir, bool value)
 Set if connection in the specified direction should be enabled.
 
virtual void SetUpOffsetsAndCosts ()
 Sets up neighbourOffsets with the current settings.
 
bool SnappedLinecast (Vector3 _a, Vector3 _b, GraphNode hint, out GraphHitInfo hit)
 Returns if _b is visible from _a on the graph.
 
void UpdateArea (GraphUpdateObject o)
 Internal function to update an area of the graph.
 
void UpdateAreaInit (GraphUpdateObject o)
 
virtual void UpdateNodePositionCollision (GridNode node, int x, int z, bool resetPenalty=true)
 Updates position, walkability and penalty for the node.
 
void UpdateSizeFromWidthDepth ()
 Updates size from width, depth and nodeSize values.
 
- Public Member Functions inherited from NavGraph
virtual void Awake ()
 This will be called on the same time as Awake on the gameObject which the AstarPath script is attached to.
 
virtual int CountNodes ()
 Count nodes in the graph.
 
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 Color NodeColor (GraphNode node, PathHandler data)
 
virtual void RelocateNodes (Matrix4x4 oldMatrix, Matrix4x4 newMatrix)
 Relocates the nodes in this graph.
 
void Scan ()
 
void ScanGraph ()
 Consider using AstarPath.Scan () instead since this function might screw things up if there is more than one graph.
 
void ScanInternal ()
 Internal method for scanning graphs.
 
void SetMatrix (Matrix4x4 m)
 Use to set both matrix and inverseMatrix at the same time.
 
- Public Member Functions inherited from IUpdatableGraph
GraphUpdateThreading CanUpdateAsync (GraphUpdateObject o)
 
void UpdateArea (GraphUpdateObject o)
 Updates an area using the specified GraphUpdateObject.
 
void UpdateAreaInit (GraphUpdateObject o)
 
- Public Member Functions inherited from IRaycastableGraph
bool Linecast (Vector3 start, Vector3 end)
 
bool Linecast (Vector3 start, Vector3 end, GraphNode hint)
 
bool Linecast (Vector3 start, Vector3 end, GraphNode hint, out GraphHitInfo hit)
 
bool Linecast (Vector3 start, Vector3 end, GraphNode hint, out GraphHitInfo hit, List< GraphNode > trace)
 

Static Public Member Functions

static void CalculateConnections (GridNode node)
 Calculates the grid connections for a single node.
 
- Static Public Member Functions inherited from NavGraph
static bool InSearchTree (GraphNode node, Path path)
 Returns if the node is in the search tree of the path.
 

Public Attributes

Matrix4x4 boundsMatrix
 
Matrix4x4 boundsMatrix2
 
const int getNearestForceOverlap = 2
 In GetNearestForce, determines how far to search after a valid node has been found.
 
readonly uint[] neighbourCosts = new uint[8]
 Costs to neighbour nodes.
 
readonly int[] neighbourOffsets = new int[8]
 Index offset to get neighbour nodes.
 
readonly int[] neighbourXOffsets = new int[8]
 Offsets in the X direction for neighbour nodes.
 
readonly int[] neighbourZOffsets = new int[8]
 Offsets in the Z direction for neighbour nodes.
 
GridNode[] nodes
 All nodes in this graph.
 
Vector2 size
 Size of the grid.
 
- Public Attributes inherited from NavGraph
byte[] _sguid
 Used to store the guid value.
 
AstarPath active
 Reference to the AstarPath object in the scene.
 
bool drawGizmos = true
 
uint graphIndex
 Index of the graph, used for identification purposes.
 
bool infoScreenOpen
 Used in the editor to check if the info screen is open.
 
uint initialPenalty = 0
 Default penalty to apply to all nodes.
 
Matrix4x4 inverseMatrix = Matrix4x4.identity
 Inverse of matrix.
 
Matrix4x4 matrix = Matrix4x4.identity
 A matrix for translating/rotating/scaling the graph.
 
string name
 Name of the graph.
 
bool open
 Is the graph open in the editor.
 

Static Protected Member Functions

static void GetBoundsMinMax (Bounds b, Matrix4x4 matrix, out Vector3 min, out Vector3 max)
 Calculates minimum and maximum points for bounds b when multiplied with the matrix.
 

Protected Attributes

int[] corners
 Small buffer to reduce memory allocations.
 

Properties

int Depth [get, set]
 
virtual bool uniformWidthDepthGrid [get]
 This is placed here so generators inheriting from this one can override it and set it to false.
 
int Width [get, set]
 
- Properties inherited from NavGraph
Guid guid [get, set]
 Used as an ID of the graph, considered to be unique.
 

Private Member Functions

bool ErosionAnyFalseConnections (GridNode node)
 True if the node has any blocked connections.
 
GridNode GetNodeConnection (int index, int x, int z, int dir)
 Get the connecting node from the node at (x,z) in the specified direction.
 
List< GraphNodeGetNodesInArea (Bounds b, GraphUpdateShape shape)
 All nodes inside the shape or if null, the bounding box.
 
void RemoveGridGraphFromStatic ()
 

Static Private Attributes

static readonly int[] hexagonNeighbourIndices = new int[6] { 0, 1, 2, 3, 5, 7 }
 

Inspector - Settings

bool useRaycastNormal [get]
 Use heigh raycasting normal for max slope calculation.
 
int width
 Width of the grid in nodes.
 
int depth
 Depth (height) of the grid in nodes.
 
float aspectRatio = 1F
 Scaling of the graph along the X axis.
 
float isometricAngle = 0
 Angle to use for the isometric projection.
 
bool uniformEdgeCosts = false
 If true, all edge costs will be set to the same value.
 
Vector3 rotation
 Rotation of the grid in degrees.
 
Bounds bounds
 
Vector3 center
 Center point of the grid.
 
Vector2 unclampedSize
 Size of the grid.
 
float nodeSize = 1
 Size of one node in world units.
 
GraphCollision collision
 Settings on how to check for walkability and height.
 
float maxClimb = 0.4F
 The max position difference between two nodes to enable a connection.
 
int maxClimbAxis = 1
 The axis to use for maxClimb.
 
float maxSlope = 90
 The max slope in degrees for a node to be walkable.
 
int erodeIterations = 0
 Erosion of the graph.
 
bool erosionUseTags = false
 Use tags instead of walkability for erosion.
 
int erosionFirstTag = 1
 Tag to start from when using tags for erosion.
 
bool autoLinkGrids = false
 Auto link the graph's edge nodes together with other GridGraphs in the scene on Scan.
 
float autoLinkDistLimit = 10F
 Distance limit for grid graphs to be auto linked.
 
NumNeighbours neighbours = NumNeighbours.Eight
 Number of neighbours for each node.
 
bool cutCorners = true
 If disabled, will not cut corners on obstacles.
 
float penaltyPositionOffset = 0
 Offset for the position when calculating penalty.
 
bool penaltyPosition = false
 Use position (y-coordinate) to calculate penalty.
 
float penaltyPositionFactor = 1F
 Scale factor for penalty when calculating from position.
 
bool penaltyAngle = false
 
float penaltyAngleFactor = 100F
 How much penalty is applied depending on the slope of the terrain.
 
float penaltyAnglePower = 1
 How much extra to penalize very steep angles.
 
bool useJumpPointSearch = false
 
TextureData textureData = new TextureData ()
 Holds settings for using a texture as source for a grid graph.
 

Constructor & Destructor Documentation

GridGraph ( )

Member Function Documentation

static void CalculateConnections ( GridNode  node)
static

Calculates the grid connections for a single node.

Convenience function, it's faster to use CalculateConnections(GridNode[],int,int,node) but that will only show when calculating for a large number of nodes

Todo:
Test this function, should work ok, but you never know
virtual void CalculateConnections ( GridNode[]  nodes,
int  x,
int  z,
GridNode  node 
)
virtual

Calculates the grid connections for a single node.

GraphUpdateThreading CanUpdateAsync ( GraphUpdateObject  o)
bool CheckConnection ( GridNode  node,
int  dir 
)

Returns if node is connected to it's neighbour in the specified direction.

This will also return true if neighbours = NumNeighbours.Four, the direction is diagonal and one can move through one of the adjacent nodes to the targeted node.

override void DeserializeExtraInfo ( GraphSerializationContext  ctx)
virtual

Deserializes graph type specific node data.

See Also
SerializeExtraInfo

Reimplemented from NavGraph.

Reimplemented in LayerGridGraph.

virtual void ErodeWalkableArea ( )
virtual

Erodes the walkable area.

See Also
erodeIterations
virtual void ErodeWalkableArea ( int  xmin,
int  zmin,
int  xmax,
int  zmax 
)
virtual

Erodes the walkable area.

xmin, zmin (inclusive)
xmax, zmax (exclusive)

See Also
erodeIterations

Reimplemented in LayerGridGraph.

bool ErosionAnyFalseConnections ( GridNode  node)
private

True if the node has any blocked connections.

For 4 and 8 neighbours the 4 axis aligned connections will be checked. For 6 neighbours all 6 neighbours will be checked.

void GenerateMatrix ( )

Generates the matrix used for translating nodes from grid coordinates to world coordintes.

static void GetBoundsMinMax ( Bounds  b,
Matrix4x4  matrix,
out Vector3  min,
out Vector3  max 
)
staticprotected

Calculates minimum and maximum points for bounds b when multiplied with the matrix.

uint GetConnectionCost ( int  dir)
override NNInfo GetNearest ( Vector3  position,
NNConstraint  constraint,
GraphNode  hint 
)
virtual
Todo:
Set clamped position for Grid Graph

Reimplemented from NavGraph.

Reimplemented in LayerGridGraph.

override NNInfo GetNearestForce ( Vector3  position,
NNConstraint  constraint 
)
virtual
Todo:
Set clamped position for Grid Graph

Reimplemented from NavGraph.

Reimplemented in LayerGridGraph.

GridNode GetNodeConnection ( GridNode  node,
int  dir 
)
GridNode GetNodeConnection ( int  index,
int  x,
int  z,
int  dir 
)
private

Get the connecting node from the node at (x,z) in the specified direction.

Returns
A GridNode if the node has a connection to that node. Null if no connection in that direction exists
See Also
GridNode
Int3 GetNodePosition ( int  index,
int  yOffset 
)
override void GetNodes ( GraphNodeDelegateCancelable  del)
virtual

Calls a delegate with all nodes in the graph.

This is the primary way of "looping" through all nodes in a graph.

This function should not change anything in the graph structure.

myGraph.GetNodes ((node) => {
Debug.Log ("I found a node at position " + (Vector3)node.Position);
return true;
});

Implements NavGraph.

Reimplemented in LayerGridGraph.

List<GraphNode> GetNodesInArea ( Bounds  b)

All nodes inside the bounding box.

Note
Be nice to the garbage collector and release the list when you have used it (optional)
See Also
Pathfinding.Util.ListPool
GetNodesInArea(GraphUpdateShape)
List<GraphNode> GetNodesInArea ( GraphUpdateShape  shape)

All nodes inside the shape.

Note
Be nice to the garbage collector and release the list when you have used it (optional)
See Also
Pathfinding.Util.ListPool
GetNodesInArea(Bounds)
List<GraphNode> GetNodesInArea ( Bounds  b,
GraphUpdateShape  shape 
)
private

All nodes inside the shape or if null, the bounding box.

If a shape is supplied, it is assumed to be contained inside the bounding box.

See Also
GraphUpdateShape.GetBounds
bool HasNodeConnection ( GridNode  node,
int  dir 
)
bool HasNodeConnection ( int  index,
int  x,
int  z,
int  dir 
)
virtual bool IsValidConnection ( GridNode  n1,
GridNode  n2 
)
virtual

Returns true if a connection between the adjacent nodes n1 and n2 is valid.

Also takes into account if the nodes are walkable

This method may be overriden if you want to customize what connections are valid. It must however hold that IsValidConnection(a,b) == IsValidConnection(b,a)

bool Linecast ( Vector3  _a,
Vector3  _b 
)

Returns if there is an obstacle between origin and end on the graph.

This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions.

A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
bool Linecast ( Vector3  _a,
Vector3  _b,
GraphNode  hint 
)

Returns if there is an obstacle between origin and end on the graph.

Parameters
[in]_aPoint to linecast from
[in]_bPoint to linecast to
[in]hintIf you have some idea of what the start node might be (the one close to _a), pass it to hint since it can enable faster lookups This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions.
A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
bool Linecast ( Vector3  _a,
Vector3  _b,
GraphNode  hint,
out GraphHitInfo  hit 
)

Returns if there is an obstacle between origin and end on the graph.

Parameters
[in]_aPoint to linecast from
[in]_bPoint to linecast to
[out]hitContains info on what was hit, see GraphHitInfo
[in]hintIf you have some idea of what the start node might be (the one close to _a), pass it to hint since it can enable faster lookups This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions.
A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
bool Linecast ( Vector3  _a,
Vector3  _b,
GraphNode  hint,
out GraphHitInfo  hit,
List< GraphNode trace 
)

Returns if there is an obstacle between origin and end on the graph.

Parameters
[in]_aPoint to linecast from
[in]_bPoint to linecast to
[out]hitContains info on what was hit, see GraphHitInfo
[in]hintIf you have some idea of what the start node might be (the one close to _a), pass it to hint since it can enable faster lookups
traceIf a list is passed, then it will be filled with all nodes the linecast traverses This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions.
A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
override void OnDestroy ( )
virtual

This function will be called when this graph is destroyed.

Reimplemented from NavGraph.

Reimplemented in LayerGridGraph.

override void OnDrawGizmos ( bool  drawNodes)
virtual

Draw gizmos for the graph.

Reimplemented from NavGraph.

Reimplemented in LayerGridGraph.

void OnPostScan ( AstarPath  script)

Auto links grid graphs together.

Called after all graphs have been scanned.

See Also
autoLinkGrids
override 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 from NavGraph.

Reimplemented in LayerGridGraph.

void RelocateNodes ( Vector3  center,
Quaternion  rotation,
float  nodeSize,
float  aspectRatio = 1,
float  isometricAngle = 0 
)

Relocate the grid graph using new settings.

Warning
This method is lossy, so calling it many times may cause node positions to loose precision. For example if you set the nodeSize to 0 in one call, and then to 1 in the next call, it will not be able to recover the correct positions since when the nodeSize was 0, all nodes were scaled/moved to the same point. The same thing happens for other - less extreme - values as well, but to a lesser degree.
void RemoveGridGraphFromStatic ( )
private
override void ScanInternal ( OnScanStatus  statusCallback)
virtual

Scans the graph, called from AstarPath.ScanInternal Override this function to implement custom scanning logic The statusCallback may be optionally called to show progress info in the editor

Implements NavGraph.

Reimplemented in LayerGridGraph.

override void SerializeExtraInfo ( GraphSerializationContext  ctx)
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.

Reimplemented from NavGraph.

Reimplemented in LayerGridGraph.

void SetNodeConnection ( GridNode  node,
int  dir,
bool  value 
)
void SetNodeConnection ( int  index,
int  x,
int  z,
int  dir,
bool  value 
)

Set if connection in the specified direction should be enabled.

Note that bounds checking will still be done when getting the connection value again, so it is not necessarily true that HasNodeConnection will return true just because you used SetNodeConnection on a node to set a connection to true.

Parameters
indexIndex of the node
xX coordinate of the node
zZ coordinate of the node
valueEnable or disable the connection
Note
This is identical to Pathfinding.Node.SetConnectionInternal
Deprecated:
virtual void SetUpOffsetsAndCosts ( )
virtual

Sets up neighbourOffsets with the current settings.

neighbourOffsets, neighbourCosts, neighbourXOffsets and neighbourZOffsets are set up.
The cost for a non-diagonal movement between two adjacent nodes is RoundToInt (nodeSize * Int3.Precision)
The cost for a diagonal movement between two adjacent nodes is RoundToInt (nodeSize * Sqrt (2) * Int3.Precision)

bool SnappedLinecast ( Vector3  _a,
Vector3  _b,
GraphNode  hint,
out GraphHitInfo  hit 
)

Returns if _b is visible from _a on the graph.

This function is different from the other Linecast functions since it 1) snaps the start and end positions directly to the graph and it uses Bresenham's line drawing algorithm as opposed to the others which use sampling at fixed intervals. If you only care about if one node can see another node, then this function is great, but if you need more precision than one node, use the normal linecast functions

Parameters
[in]_aPoint to linecast from
[in]_bPoint to linecast to
[out]hitContains info on what was hit, see GraphHitInfo
[in]hintIf you have some idea of what the start node might be (the one close to _a), pass it to hint since it can enable faster lookups

This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions.

A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
See Also
https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
void UpdateArea ( GraphUpdateObject  o)

Internal function to update an area of the graph.

void UpdateAreaInit ( GraphUpdateObject  o)
virtual void UpdateNodePositionCollision ( GridNode  node,
int  x,
int  z,
bool  resetPenalty = true 
)
virtual

Updates position, walkability and penalty for the node.

Assumes that collision.Initialize (...) has been called before this function

void UpdateSizeFromWidthDepth ( )

Updates size from width, depth and nodeSize values.

Also generates a new matrix .

Note
This does not rescan the graph, that must be done with Scan

Member Data Documentation

float aspectRatio = 1F

Scaling of the graph along the X axis.

This should be used if you want different scales on the X and Y axis of the grid

float autoLinkDistLimit = 10F

Distance limit for grid graphs to be auto linked.

Warning
This feature is experimental and it is currently disabled.
See Also
autoLinkGrids
bool autoLinkGrids = false

Auto link the graph's edge nodes together with other GridGraphs in the scene on Scan.

Warning
This feature is experimental and it is currently disabled.
See Also
autoLinkDistLimit
Bounds bounds
Matrix4x4 boundsMatrix
Matrix4x4 boundsMatrix2
Vector3 center

Center point of the grid.

GraphCollision collision

Settings on how to check for walkability and height.

int [] corners
protected

Small buffer to reduce memory allocations.

Used in the CalculateConnections function

See Also
CalculateConnections
bool cutCorners = true

If disabled, will not cut corners on obstacles.

If connections is Eight, obstacle corners might be cut by a connection, setting this to false disables that.

cutCorners.png
int depth

Depth (height) of the grid in nodes.

See Also
UpdateSizeFromWidthDepth
int erodeIterations = 0

Erosion of the graph.

The graph can be eroded after calculation. This means a margin is put around unwalkable nodes or other unwalkable connections. It is really good if your graph contains ledges where the nodes without erosion are walkable too close to the edge.

Below is an image showing a graph with erode iterations 0, 1 and 2

Note
A high number of erode iterations can seriously slow down graph updates during runtime (GraphUpdateObject) and should be kept as low as possible.
See Also
erosionUseTags
int erosionFirstTag = 1

Tag to start from when using tags for erosion.

See Also
erosionUseTags
erodeIterations
bool erosionUseTags = false

Use tags instead of walkability for erosion.

Tags will be used for erosion instead of marking nodes as unwalkable. The nodes will be marked with tags in an increasing order starting with the tag erosionFirstTag. Debug with the Tags mode to see the effect. With this enabled you can in effect set how close different AIs are allowed to get to walls using the Valid Tags field on the Seeker component.

See Also
erosionFirstTag
const int getNearestForceOverlap = 2

In GetNearestForce, determines how far to search after a valid node has been found.

readonly int [] hexagonNeighbourIndices = new int[6] { 0, 1, 2, 3, 5, 7 }
staticprivate
float isometricAngle = 0

Angle to use for the isometric projection.

If you are making a 2D isometric game, you may want to use this parameter to adjust the layout of the graph to match your game. This will essentially scale the graph along one of its diagonals to produce something like this:

A perspective view of an isometric graph.

A top down view of an isometric graph. Note that the graph is entirely 2D, there is no perspective in this image.

Usually the angle that you want to use is either 30 degrees (alternatively 90-30 = 60 degrees) or atan(1/sqrt(2)) which is approximately 35.264 degrees (alternatively 90 - 35.264 = 54.736 degrees). You might also want to rotate the graph plus or minus 45 degrees around the Y axis to get the oritientation required for your game.

You can read more about it on the wikipedia page linked below.

See Also
http://en.wikipedia.org/wiki/Isometric_projection
rotation
float maxClimb = 0.4F

The max position difference between two nodes to enable a connection.

Set to 0 to ignore the value.

int maxClimbAxis = 1

The axis to use for maxClimb.

X = 0, Y = 1, Z = 2.

float maxSlope = 90

The max slope in degrees for a node to be walkable.

readonly uint [] neighbourCosts = new uint[8]

Costs to neighbour nodes.

readonly int [] neighbourOffsets = new int[8]

Index offset to get neighbour nodes.

Added to a node's index to get a neighbour node index.

Z | |

6 2 5 \ | / – 3 - X - 1 —– X / | \ 7 0 4

| |

NumNeighbours neighbours = NumNeighbours.Eight

Number of neighbours for each node.

Either four directional or eight directional

readonly int [] neighbourXOffsets = new int[8]

Offsets in the X direction for neighbour nodes.

Only 1, 0 or -1

readonly int [] neighbourZOffsets = new int[8]

Offsets in the Z direction for neighbour nodes.

Only 1, 0 or -1

GridNode [] nodes

All nodes in this graph.

float nodeSize = 1

Size of one node in world units.

See Also
UpdateSizeFromWidthDepth
bool penaltyAngle = false
float penaltyAngleFactor = 100F

How much penalty is applied depending on the slope of the terrain.

At a 90 degree slope (not that exactly 90 degree slopes can occur, but almost 90 degree), this penalty is applied. At a 45 degree slope, half of this is applied and so on. Note that you may require very large values, a value of 1000 is equivalent to the cost of moving 1 world unit.

float penaltyAnglePower = 1

How much extra to penalize very steep angles.

bool penaltyPosition = false

Use position (y-coordinate) to calculate penalty.

float penaltyPositionFactor = 1F

Scale factor for penalty when calculating from position.

See Also
penaltyPosition
float penaltyPositionOffset = 0

Offset for the position when calculating penalty.

See Also
penaltyPosition
Vector3 rotation

Rotation of the grid in degrees.

Vector2 size

Size of the grid.

Will always be positive and larger than nodeSize.

See Also
GenerateMatrix
TextureData textureData = new TextureData ()

Holds settings for using a texture as source for a grid graph.

Texure data can be used for fine grained control over how the graph will look. It can be used for positioning, penalty and walkability control.
Below is a screenshot of a grid graph with a penalty map applied. It has the effect of the AI taking the longer path along the green (low penalty) areas.

Color data is got as 0...255 values.
A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
Warning
Can only be used with Unity 3.4 and up
Vector2 unclampedSize

Size of the grid.

Might be negative or smaller than nodeSize

bool uniformEdgeCosts = false

If true, all edge costs will be set to the same value.

If false, diagonals will cost more. This is useful for a hexagon graph where the diagonals are actually the same length as the normal edges (since the graph has been skewed)

bool useJumpPointSearch = false
int width

Width of the grid in nodes.

See Also
UpdateSizeFromWidthDepth

Property Documentation

int Depth
getset
virtual bool uniformWidthDepthGrid
get

This is placed here so generators inheriting from this one can override it and set it to false.

If it is true, it means that the nodes array's length will always be equal to width*depth It is used mainly in the editor to do auto-scanning calls, setting it to false for a non-uniform grid will reduce the number of scans

bool useRaycastNormal
get

Use heigh raycasting normal for max slope calculation.

True if maxSlope is less than 90 degrees.

int Width
getset

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