Class ProceduralGridMover Extends VersionedMonoBehaviour
Moves a grid graph to follow a target.
Attach this to some object in the scene and assign the target to e.g the player. Then the graph will follow that object around as it moves.
This is useful if pathfinding is only necessary in a small region around an object (for example the player). It makes it possible to have vast open worlds (maybe procedurally generated) and still be able to use pathfinding on them.
When the graph is moved you may notice an fps drop. If this grows too large you can try a few things:
Reduce the updateDistance. This will make the updates smaller but more frequent. This only works to some degree however since an update has an inherent overhead.
Reduce the grid size.
Turn on multithreading (A* Inspector -> Settings)
Disable Height Testing or Collision Testing in the grid graph. This can give a performance boost since fewer calls to the physics engine need to be done.
Avoid using any erosion in the grid graph settings. This is relatively slow.
This script has a built-in constant called MaxMillisPerFrame and it tries to not use any more cpu time than that per frame.
Make sure you have 'Show Graphs' disabled in the A* inspector since gizmos in the scene view can take some time to update when the graph moves and thus make it seem like this script is slower than it actually is.
See
Take a look at the example scene called "Procedural" for an example of how to use this script
Note
Using erosion on grid graphs can significantly lower the performance when updating graphs. Each erosion iteration requires expanding the region that is updated by 1 node.
Public Methods
Updates the graph asynchronously.
Public Variables
Grid graph to update.
Index for the graph to update.
Graph will be moved to follow this target.
Graph will be updated if the target is more than this number of nodes from the graph center.
True while the graph is being updated by this script.
Private/Protected Members
Temporary buffer.
Approximate maximum number of milliseconds this script is allowed to use for processing each frame.
Temporary buffer.
Handle serialization backwards compatibility.
Transforms a point from world space to graph space.
Handle serialization backwards compatibility.
Update is called once per frame.
Async method for moving the graph.