A* Pathfinding Project
4.3.5
The A* Pathfinding Project for Unity 3D

Stores the navigation graphs for the A* Pathfinding System. More...
Stores the navigation graphs for the A* Pathfinding System.
An instance of this class is assigned to AstarPath.data, from it you can access all graphs loaded through the graphs variable.
This class also handles a lot of the high level serialization.
Public Member Functions  
NavGraph  AddGraph (string type) 
Adds a graph of type type to the graphs array. More...  
NavGraph  AddGraph (System.Type type) 
Adds a graph of type type to the graphs array. More...  
void  Awake () 
Loads the graphs from memory, will load cached graphs if any exists. More...  
NavGraph  CreateGraph (string type) 
Creates a new instance of a graph of type type. More...  
void  DeserializeGraphs () 
Deserializes graphs from data. More...  
void  DeserializeGraphs (byte[] bytes) 
Deserializes graphs from the specified byte array. More...  
void  DeserializeGraphsAdditive (byte[] bytes) 
Deserializes graphs from the specified byte array additively. More...  
NavGraph  FindGraph (System.Func< NavGraph, bool > predicate) 
Returns the first graph which satisfies the predicate. More...  
NavGraph  FindGraphOfType (System.Type type) 
Returns the first graph of type type found in the graphs array. More...  
IEnumerable  FindGraphsOfType (System.Type type) 
Loop through this function to get all graphs of type 'type'. More...  
void  FindGraphTypes () 
Find all graph types supported in this build. More...  
NavGraph  FindGraphWhichInheritsFrom (System.Type type) 
Returns the first graph which inherits from the type type. More...  
byte []  GetData () 
int  GetGraphIndex (NavGraph graph) 
Gets the index of the NavGraph in the graphs array. More...  
System.Type  GetGraphType (string type) 
void  GetNodes (System.Action< GraphNode > callback) 
Calls the callback with every node in all graphs. More...  
IEnumerable  GetRaycastableGraphs () 
All graphs which implements the UpdateableGraph interface. More...  
IEnumerable  GetUpdateableGraphs () 
All graphs which implements the UpdateableGraph interface. More...  
void  LoadFromCache () 
Load from data from file_cachedStartup. More...  
void  OnDestroy () 
bool  RemoveGraph (NavGraph graph) 
Removes the specified graph from the graphs array and Destroys it in a safe manner. More...  
byte []  SerializeGraphs () 
Serializes all graphs settings to a byte array. More...  
byte []  SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings) 
Serializes all graphs settings and optionally node data to a byte array. More...  
byte []  SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings, out uint checksum) 
Main serializer function. More...  
void  SetData (byte[] data) 
void  UpdateShortcuts () 
Updates shortcuts to the first graph of different types. More...  
Static Public Member Functions  
static NavGraph  GetGraph (GraphNode node) 
Returns the graph which contains the specified node. More...  
Public Attributes  
bool  cacheStartup 
Should graphdata be cached. More...  
byte []  data_cachedStartup 
Serialized data for cached startup. More...  
TextAsset  file_cachedStartup 
Serialized data for cached startup. More...  
NavGraph []  graphs = new NavGraph[0] 
All graphs this instance holds. More...  
Package Functions  
NavGraph  CreateGraph (System.Type type) 
Creates a new graph instance of type type. More...  
void  LockGraphStructure (bool allowAddingGraphs=false) 
Prevent the graph structure from changing during the time this lock is held. More...  
void  UnlockGraphStructure () 
Allows the graph structure to change again. More...  
Properties  
static AstarPath  active [get] 
Shortcut to AstarPath.active. More...  
byte []  data [get, set] 
Serialized data for all graphs and settings. More...  
System.Type []  graphTypes [get, private set] 
All supported graph types. More...  
GridGraph  gridGraph [get, private set] 
Shortcut to the first GridGraph. More...  
LayerGridGraph  layerGridGraph [get, private set] 
Shortcut to the first LayerGridGraph. More...  
NavMeshGraph  navmesh [get, private set] 
Shortcut to the first NavMeshGraph. More...  
PointGraph  pointGraph [get, private set] 
Shortcut to the first PointGraph. More...  
RecastGraph  recastGraph [get, private set] 
Shortcut to the first RecastGraph. More...  
Private Member Functions  
void  AddGraph (NavGraph graph) 
Adds the specified graph to the graphs array. More...  
PathProcessor.GraphUpdateLock  AssertSafe (bool onlyAddingGraph=false) 
void  ClearGraphs () 
Destroys all graphs and sets graphs to null. More...  
void  DeserializeGraphsPartAdditive (Pathfinding.Serialization.AstarSerializer sr) 
Helper function for deserializing graphs. More...  
Private Attributes  
string  dataString 
Serialized data for all graphs and settings. More...  
List< bool >  graphStructureLocked = new List<bool>() 
byte []  upgradeData 
Data from versions from before 3.6.1. More...  
NavGraph AddGraph  (  System.Type  type  ) 
Adds a graph of type type to the graphs array.

private 
void Awake  (  ) 
Loads the graphs from memory, will load cached graphs if any exists.

private 
Destroys all graphs and sets graphs to null.
NavGraph CreateGraph  (  string  type  ) 
Creates a new instance of a graph of type type.
If no matching graph type was found, an error is logged and null is returned

package 
Creates a new graph instance of type type.
void DeserializeGraphs  (  ) 
Deserializes graphs from data.
void DeserializeGraphs  (  byte []  bytes  ) 
Deserializes graphs from the specified byte array.
An error will be logged if deserialization fails.
void DeserializeGraphsAdditive  (  byte []  bytes  ) 
Deserializes graphs from the specified byte array additively.
An error will be logged if deserialization fails. This function will add loaded graphs to the current ones.

private 
Helper function for deserializing graphs.
Returns the first graph which satisfies the predicate.
Returns null if no graph was found.
NavGraph FindGraphOfType  (  System.Type  type  ) 
Returns the first graph of type type found in the graphs array.
Returns null if no graph was found.
IEnumerable FindGraphsOfType  (  System.Type  type  ) 
void FindGraphTypes  (  ) 
Find all graph types supported in this build.
Using reflection, the assembly is searched for types which inherit from NavGraph.
NavGraph FindGraphWhichInheritsFrom  (  System.Type  type  ) 
Returns the first graph which inherits from the type type.
Returns null if no graph was found.
byte [] GetData  (  ) 
Returns the graph which contains the specified node.
The graph must be in the graphs array.
System.Type GetGraphType  (  string  type  ) 
void GetNodes  (  System.Action< GraphNode >  callback  ) 
Calls the callback with every node in all graphs.
This is the easiest way to iterate through every existing node.
IEnumerable GetRaycastableGraphs  (  ) 
All graphs which implements the UpdateableGraph interface.
IEnumerable GetUpdateableGraphs  (  ) 
All graphs which implements the UpdateableGraph interface.
void LoadFromCache  (  ) 
Load from data from file_cachedStartup.

package 
Prevent the graph structure from changing during the time this lock is held.
This prevents graphs from being added or removed and also prevents graphs from being serialized or deserialized. This is used when e.g an async scan is happening to ensure that for example a graph that is being scanned is not destroyed.
Each call to this method *must* be paired with exactly one call to UnlockGraphStructure. The calls may be nested.
void OnDestroy  (  ) 
bool RemoveGraph  (  NavGraph  graph  ) 
Removes the specified graph from the graphs array and Destroys it in a safe manner.
To avoid changing graph indices for the other graphs, the graph is simply nulled in the array instead of actually removing it from the array. The empty position will be reused if a new graph is added.
byte [] SerializeGraphs  (  ) 
Serializes all graphs settings to a byte array.
byte [] SerializeGraphs  (  Pathfinding.Serialization.SerializeSettings  settings  ) 
Serializes all graphs settings and optionally node data to a byte array.
byte [] SerializeGraphs  (  Pathfinding.Serialization.SerializeSettings  settings, 
out uint  checksum  
) 
Main serializer function.
Serializes all graphs to a byte array A similar function exists in the AstarPathEditor.cs script to save additional info
void SetData  (  byte []  data  ) 

package 
Allows the graph structure to change again.
void UpdateShortcuts  (  ) 
Updates shortcuts to the first graph of different types.
Hard coding references to some graph types is not really a good thing imo. I want to keep it dynamic and flexible. But these references ease the use of the system, so I decided to keep them.
bool cacheStartup 
Should graphdata be cached.
Caching the startup means saving the whole graphs  not only the settings  to a file (file_cachedStartup) which can be loaded when the game starts. This is usually much faster than scanning the graphs when the game starts. This is configured from the editor under the "Save & Load" tab.
byte [] data_cachedStartup 
Serialized data for cached startup.

private 
TextAsset file_cachedStartup 
Serialized data for cached startup.
If set, on start the graphs will be deserialized from this file.
All graphs this instance holds.
This will be filled only after deserialization has completed. May contain null entries if graph have been removed.

private 

private 
Data from versions from before 3.6.1.
Used for handling upgrades

staticget 
Shortcut to AstarPath.active.

getsetprivate 
Serialized data for all graphs and settings.

getprivate set 
All supported graph types.
Populated through reflection search

getprivate set 
Shortcut to the first LayerGridGraph.
Updated at scanning time.

getprivate set 
Shortcut to the first NavMeshGraph.
Updated at scanning time

getprivate set 
Shortcut to the first PointGraph.
Updated at scanning time

getprivate set 
Shortcut to the first RecastGraph.
Updated at scanning time.