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

Helper class for easily updating graphs. More...

Detailed Description

Helper class for easily updating graphs.

See Also
Graph Updates during Runtime for an explanation of how to use this class.

Public Member Functions

void Apply (AstarPath active)
 Apply the update.
 
void Apply ()
 Updates graphs with a created GUO.
 
Bounds GetBounds ()
 Calculates the bounds for this component.
 
virtual void InvertSettings ()
 Inverts all invertable settings for this GUS.
 
void LockToY ()
 Lock all points to a specific Y value.
 
void OnDrawGizmos ()
 Draws some gizmos.
 
void OnDrawGizmos (bool selected)
 Draws some gizmos.
 
void OnDrawGizmosSelected ()
 Draws some gizmos.
 
override void OnPostScan ()
 Called right after all graphs have been scanned.
 
void RecalcConvex ()
 Recalculate convex points.
 
void Start ()
 Do some stuff at start.
 
void ToggleUseWorldSpace ()
 Switches between using world space and using local space.
 
- Public Member Functions inherited from GraphModifier
virtual void OnGraphsPostUpdate ()
 Called after graphs have been updated using GraphUpdateObjects.
 
virtual void OnGraphsPreUpdate ()
 Called before graphs are updated using GraphUpdateObjects.
 
virtual void OnLatePostScan ()
 Called at the end of the scanning procedure.
 
virtual void OnPostCacheLoad ()
 Called after cached graphs have been loaded.
 
virtual void OnPreScan ()
 Called right before graphs are going to be scanned.
 

Public Attributes

bool applyOnScan = true
 Apply this graph update object whenever a graph is rescanned.
 
bool applyOnStart = true
 Apply this graph update object on start.
 
bool convex = true
 Use the convex hull (XZ space) of the points.
 
bool lockToY = false
 Lock all points to Y = lockToYValue.
 
float lockToYValue = 0
 if lockToY is enabled lock all points to this value
 
float minBoundsHeight = 1
 Minumum height of the bounds of the resulting Graph Update Object.
 
bool modifyTag = false
 If enabled, set all nodes' tags to setTag.
 
bool modifyWalkability = false
 Set to true to set all targeted nodese walkability to setWalkability.
 
int penaltyDelta = 0
 Penalty to add to nodes.
 
Vector3[] points
 Points which define the region to update.
 
bool resetPenaltyOnPhysics = true
 When updatePhysics is true, GridGraphs will normally reset penalties, with this option you can override it.
 
int setTag = 0
 If modifyTag is enabled, set all nodes' tags to this value.
 
bool setWalkability = false
 See modifyWalkability.
 
bool updateErosion = true
 Update Erosion for GridGraphs.
 
bool updatePhysics = false
 Update node's walkability and connectivity using physics functions.
 
bool useWorldSpace = false
 Use world space for coordinates.
 

Private Attributes

Vector3[] convexPoints
 Private cached convex hull of the points.
 
bool firstApplied = false
 Has apply been called yet.
 
int setTagInvert = 0
 Private cached inversion of setTag.
 

Additional Inherited Members

- Public Types inherited from GraphModifier
enum  EventType {
  PostScan = 1 << 0, PreScan = 1 << 1, LatePostScan = 1 << 2, PreUpdate = 1 << 3,
  PostUpdate = 1 << 4, PostCacheLoad = 1 << 5
}
 GraphModifier event type. More...
 
- Static Public Member Functions inherited from GraphModifier
static void FindAllModifiers ()
 
static void TriggerEvent (GraphModifier.EventType type)
 Triggers an event for all active graph modifiers.
 
- Protected Member Functions inherited from GraphModifier
virtual void OnDisable ()
 Removes this modifier from list of active modifiers.
 
virtual void OnEnable ()
 Adds this modifier to list of active modifiers.
 

Member Function Documentation

void Apply ( AstarPath  active)

Apply the update.

Will only do anything if applyOnScan is enabled

void Apply ( )

Updates graphs with a created GUO.

Creates a Pathfinding.GraphUpdateObject with a Pathfinding.GraphUpdateShape representing the polygon of this object and update all graphs using AstarPath.UpdateGraphs. This will not update graphs directly. See AstarPath.UpdateGraph for more info.

Bounds GetBounds ( )

Calculates the bounds for this component.

This is a relatively expensive operation, it needs to go through all points and sometimes do matrix multiplications.

virtual void InvertSettings ( )
virtual

Inverts all invertable settings for this GUS.

Namely: penalty delta, walkability, tags.

Penalty delta will be changed to negative penalty delta.
setWalkability will be inverted.
setTag will be stored in a private variable, and the new value will be 0. When calling this function again, the saved value will be the new value.

Calling this function an even number of times without changing any settings in between will be identical to no change in settings.

void LockToY ( )

Lock all points to a specific Y value.

See Also
lockToYValue
void OnDrawGizmos ( )

Draws some gizmos.

void OnDrawGizmos ( bool  selected)

Draws some gizmos.

void OnDrawGizmosSelected ( )

Draws some gizmos.

override void OnPostScan ( )
virtual

Called right after all graphs have been scanned.

FloodFill and other post processing has not been done.

Warning
Since OnEnable and Awake are called roughly in the same time, the only way to ensure that these scripts get this call when scanning in Awake is to set the Script Execution Order for AstarPath to some time later than default time (see Edit -> Project Settings -> Script Execution Order).
See Also
OnLatePostScan

Reimplemented from GraphModifier.

void RecalcConvex ( )

Recalculate convex points.

Will not do anything if not convex is enabled

void Start ( )

Do some stuff at start.

void ToggleUseWorldSpace ( )

Switches between using world space and using local space.

Changes point coordinates to stay the same in world space after the change.

See Also
useWorldSpace

Member Data Documentation

bool applyOnScan = true

Apply this graph update object whenever a graph is rescanned.

bool applyOnStart = true

Apply this graph update object on start.

bool convex = true

Use the convex hull (XZ space) of the points.

Vector3 [] convexPoints
private

Private cached convex hull of the points.

bool firstApplied = false
private

Has apply been called yet.

Used to prevent applying twice when both applyOnScan and applyOnStart are enabled

bool lockToY = false

Lock all points to Y = lockToYValue.

float lockToYValue = 0

if lockToY is enabled lock all points to this value

float minBoundsHeight = 1

Minumum height of the bounds of the resulting Graph Update Object.

Useful when all points are laid out on a plane but you still need a bounds with a height greater than zero since a zero height graph update object would usually result in no nodes being updated.

bool modifyTag = false

If enabled, set all nodes' tags to setTag.

bool modifyWalkability = false

Set to true to set all targeted nodese walkability to setWalkability.

int penaltyDelta = 0

Penalty to add to nodes.

Be careful when setting negative values since if a node get's a negative penalty it will underflow and instead get really large. In most cases a warning will be logged if that happens.

Vector3 [] points

Points which define the region to update.

bool resetPenaltyOnPhysics = true

When updatePhysics is true, GridGraphs will normally reset penalties, with this option you can override it.

Good to use when you want to keep old penalties even when you update the graph.The images below shows two overlapping graph update objects, the right one happened to be applied before the left one. They both have updatePhysics = true and are set to increase the penalty of the nodes by some amount.The first image shows the result when resetPenaltyOnPhysics is false. Both penalties are added correctly.

This second image shows when resetPenaltyOnPhysics is set to true. The first GUO is applied correctly, but then the second one (the left one) is applied and during its updating, it resets the penalties first and then adds penalty to the nodes. The result is that the penalties from both GUOs are not added together. The green patch in at the border is there because physics recalculation (recalculation of the position of the node, checking for obstacles etc.) affects a slightly larger area than the original GUO bounds because of the Grid Graph -> Collision Testing -> Diameter setting (it is enlarged by that value). So some extra nodes have their penalties reset.

int setTag = 0

If modifyTag is enabled, set all nodes' tags to this value.

int setTagInvert = 0
private

Private cached inversion of setTag.

Used for InvertSettings()

bool setWalkability = false
bool updateErosion = true

Update Erosion for GridGraphs.

When enabled, erosion will be recalculated for grid graphs after the GUO has been applied.In the below image you can see the different effects you can get with the different values.
The first image shows the graph when no GUO has been applied. The blue box is not identified as an obstacle by the graph, the reason there are unwalkable nodes around it is because there is a height difference (nodes are placed on top of the box) so erosion will be applied (an erosion value of 2 is used in this graph). The orange box is identified as an obstacle, so the area of unwalkable nodes around it is a bit larger since both erosion and collision has made nodes unwalkable.
The GUO used simply sets walkability to true, i.e making all nodes walkable.

When updateErosion=True, the reason the blue box still has unwalkable nodes around it is because there is still a height difference so erosion will still be applied. The orange box on the other hand has no height difference and all nodes are set to walkable.

When updateErosion=False, all nodes walkability are simply set to be walkable in this example.
See Also
Pathfinding.GridGraph

bool updatePhysics = false

Update node's walkability and connectivity using physics functions.

For grid graphs, this will update the node's position and walkability exactly like when doing a scan of the graph. If enabled for grid graphs, modifyWalkability will be ignored.

For Point Graphs, this will recalculate all connections which passes through the bounds of the resulting Graph Update Object using raycasts (if enabled).

bool useWorldSpace = false

Use world space for coordinates.

If true, the shape will not follow when moving around the transform.

See Also
ToggleUseWorldSpace

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