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

Stores the navigation graphs for the A* Pathfinding System. More...

Detailed Description

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.
 
NavGraph AddGraph (System.Type type)
 Adds a graph of type type to the graphs array.
 
void Awake ()
 Loads the graphs from memory, will load cached graphs if any exists.
 
NavGraph CreateGraph (string type)
 Creates a new instance of a graph of type type.
 
void DeserializeGraphs ()
 Deserializes graphs from data.
 
void DeserializeGraphs (byte[] bytes)
 Deserializes graphs from the specified byte array.
 
void DeserializeGraphsAdditive (byte[] bytes)
 Deserializes graphs from the specified byte array additively.
 
void DeserializeGraphsPart (Pathfinding.Serialization.AstarSerializer sr)
 Deserializes common info.
 
void DeserializeGraphsPartAdditive (Pathfinding.Serialization.AstarSerializer sr)
 Deserializes common info additively Common info is what is shared between the editor serialization and the runtime serializer.
 
NavGraph FindGraph (System.Func< NavGraph, bool > predicate)
 Returns the first graph which satisfies the predicate.
 
NavGraph FindGraphOfType (System.Type type)
 Returns the first graph of type type found in the graphs array.
 
IEnumerable FindGraphsOfType (System.Type type)
 Loop through this function to get all graphs of type 'type'.
 
void FindGraphTypes ()
 Find all graph types supported in this build.
 
NavGraph FindGraphWhichInheritsFrom (System.Type type)
 Returns the first graph which inherits from the type type.
 
byte[] GetData ()
 
int GetGraphIndex (NavGraph graph)
 Gets the index of the NavGraph in the graphs array.
 
System.Type GetGraphType (string type)
 
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.
 
void OnDestroy ()
 
bool RemoveGraph (NavGraph graph)
 Removes the specified graph from the graphs array and Destroys it in a safe manner.
 
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.
 
void SerializeGraphsPart (Pathfinding.Serialization.AstarSerializer sr)
 Serializes common info to the serializer.
 
void SetData (byte[] data)
 
void UpdateShortcuts ()
 Updates shortcuts to the first graph of different types.
 

Static Public Member Functions

static NavGraph GetGraph (GraphNode node)
 Returns the graph which contains the specified node.
 

Public Attributes

bool cacheStartup
 Should graph-data be cached.
 
byte[] data_backup
 Backup data if deserialization failed.
 
byte[] data_cachedStartup
 Serialized data for cached startup.
 
TextAsset file_cachedStartup
 Serialized data for cached startup.
 
NavGraph[] graphs = new NavGraph[0]
 All graphs this instance holds.
 

Package Functions

NavGraph CreateGraph (System.Type type)
 Creates a new graph instance of type type.
 

Properties

static AstarPath active [get]
 Shortcut to AstarPath.active.
 
byte[] data [get, set]
 Serialized data for all graphs and settings.
 
System.Type[] graphTypes [get, set]
 All supported graph types.
 
GridGraph gridGraph [get, set]
 Shortcut to the first GridGraph.
 
LayerGridGraph layerGridGraph [get, set]
 Shortcut to the first LayerGridGraph.
 
NavMeshGraph navmesh [get, set]
 Shortcut to the first NavMeshGraph.
 
PointGraph pointGraph [get, set]
 Shortcut to the first PointGraph.
 
RecastGraph recastGraph [get, set]
 Shortcut to the first RecastGraph.
 

Private Member Functions

void AddGraph (NavGraph graph)
 Adds the specified graph to the graphs array.
 
void ClearGraphs ()
 Destroys all graphs and sets graphs to null.
 

Private Attributes

string dataString
 Serialized data for all graphs and settings.
 
byte[] upgradeData
 Data from versions from before 3.6.1.
 

Member Function Documentation

NavGraph AddGraph ( string  type)

Adds a graph of type type to the graphs array.

Deprecated:
NavGraph AddGraph ( System.Type  type)

Adds a graph of type type to the graphs array.

void AddGraph ( NavGraph  graph)
private

Adds the specified graph to the graphs array.

void Awake ( )

Loads the graphs from memory, will load cached graphs if any exists.

void ClearGraphs ( )
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

Returns
The created graph
See Also
CreateGraph(System.Type)
Deprecated:
NavGraph CreateGraph ( System.Type  type)
package

Creates a new graph instance of type type.

See Also
CreateGraph(string)
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.

void DeserializeGraphsPart ( Pathfinding.Serialization.AstarSerializer  sr)

Deserializes common info.

Common info is what is shared between the editor serialization and the runtime serializer. This is mostly everything except the graph inspectors which serialize some extra data in the editor

In most cases you should use the DeserializeGraphs or DeserializeGraphsAdditive method instead.

void DeserializeGraphsPartAdditive ( Pathfinding.Serialization.AstarSerializer  sr)

Deserializes common info additively Common info is what is shared between the editor serialization and the runtime serializer.

This is mostly everything except the graph inspectors which serialize some extra data in the editor

In most cases you should use the DeserializeGraphs or DeserializeGraphsAdditive method instead.

NavGraph FindGraph ( System.Func< NavGraph, bool >  predicate)

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)

Loop through this function to get all graphs of type 'type'.

foreach (GridGraph graph in AstarPath.data.FindGraphsOfType (typeof(GridGraph))) {
//Do something with the graph
}
See Also
AstarPath.RegisterSafeNodeUpdate
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 ( )
static NavGraph GetGraph ( GraphNode  node)
static

Returns the graph which contains the specified node.

The graph must be in the graphs array.

Returns
Returns the graph which contains the node. Null if the graph wasn't found
int GetGraphIndex ( NavGraph  graph)

Gets the index of the NavGraph in the graphs array.

System.Type GetGraphType ( string  type)
Returns
A System.Type which matches the specified type string. If no mathing graph type was found, null is returned
Deprecated:
IEnumerable GetRaycastableGraphs ( )

All graphs which implements the UpdateableGraph interface.

foreach (IRaycastableGraph graph in AstarPath.data.GetRaycastableGraphs ()) {
//Do something with the graph
}
See Also
Pathfinding.IRaycastableGraph
Deprecated:
Deprecated because it is not used by the package internally and the use cases are few. Iterate through the graphs array instead.
IEnumerable GetUpdateableGraphs ( )

All graphs which implements the UpdateableGraph interface.

foreach (IUpdatableGraph graph in AstarPath.data.GetUpdateableGraphs ()) {
//Do something with the graph
}
See Also
AstarPath.AddWorkItem
Pathfinding.IUpdatableGraph
void LoadFromCache ( )

Load from data from file_cachedStartup.

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.

Returns
True if the graph was sucessfully removed (i.e it did exist in the graphs array). False otherwise.
Version
Changed in 3.2.5 to call SafeOnDestroy before removing and nulling it in the array instead of removing the element completely in the graphs array.
byte [] SerializeGraphs ( )

Serializes all graphs settings to a byte array.

See Also
DeserializeGraphs(byte[])
byte [] SerializeGraphs ( Pathfinding.Serialization.SerializeSettings  settings)

Serializes all graphs settings and optionally node data to a byte array.

See Also
DeserializeGraphs(byte[])
Pathfinding.Serialization.SerializeSettings
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 SerializeGraphsPart ( Pathfinding.Serialization.AstarSerializer  sr)

Serializes common info to the serializer.

Common info is what is shared between the editor serialization and the runtime serializer. This is mostly everything except the graph inspectors which serialize some extra data in the editor

void SetData ( byte[]  data)
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.

Member Data Documentation

bool cacheStartup

Should graph-data be cached.

Caching the startup means saving the whole graphs, not only the settings to an internal array (data_cachedStartup) which can be loaded faster than scanning all graphs at startup. This is setup from the editor.

byte [] data_backup

Backup data if deserialization failed.

byte [] data_cachedStartup

Serialized data for cached startup.

Deprecated:
Deprecated since 3.6, AstarData.file_cachedStartup is now used instead
string dataString
private

Serialized data for all graphs and settings.

Stored as a base64 encoded string because otherwise Unity's Undo system would sometimes corrupt the byte data (because it only stores deltas).

This can be accessed as a byte array from the data property.

Since
3.6.1
TextAsset file_cachedStartup

Serialized data for cached startup.

If set, on start the graphs will be deserialized from this file.

NavGraph [] graphs = new NavGraph[0]

All graphs this instance holds.

This will be filled only after deserialization has completed. May contain null entries if graph have been removed.

byte [] upgradeData
private

Data from versions from before 3.6.1.

Used for handling upgrades

Since
3.6.1

Property Documentation

AstarPath active
staticget

Shortcut to AstarPath.active.

byte [] data
getsetprivate

Serialized data for all graphs and settings.

System.Type [] graphTypes
getset

All supported graph types.

Populated through reflection search

GridGraph gridGraph
getset

Shortcut to the first GridGraph.

Updated at scanning time

LayerGridGraph layerGridGraph
getset

Shortcut to the first LayerGridGraph.

Updated at scanning time.

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
NavMeshGraph navmesh
getset

Shortcut to the first NavMeshGraph.

Updated at scanning time

PointGraph pointGraph
getset

Shortcut to the first PointGraph.

Updated at scanning time

RecastGraph recastGraph
getset

Shortcut to the first RecastGraph.

Updated at scanning time.

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

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