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

Explicit mesh object for recast graphs. More...

Detailed Description

Explicit mesh object for recast graphs.

Adding this component to an object will make sure it is included in any recast graphs. It will be included even though the Rasterize Meshes toggle is set to false.

Using RecastMeshObjs instead of relying on the Rasterize Meshes option is good for several reasons.

  • Rasterize Meshes is slow. If you are using a tiled graph and you are updaing it, every time something is recalculated the graph will have to search all meshes in your scene for ones to rasterize, in contrast, RecastMeshObjs are stored in a tree for extreamly fast lookup (O(log n + k) compared to O(n) where n is the number of meshes in your scene and k is the number of meshes which should be rasterized, if you know Big-O notation).
  • The RecastMeshObj exposes some options which can not be accessed using the Rasterize Meshes toggle. See member documentation for more info. This can for example be used to include meshes in the recast graph rasterization, but make sure that the character cannot walk on them.

Since the objects are stored in a tree, and trees are slow to update, there is an enforcement that objects are not allowed to move unless the dynamic option is enabled. When the dynamic option is enabled, the object will be stored in an array instead of in the tree. This will reduce the performance improvement over 'Rasterize Meshes' but is still faster.

If a mesh filter and a mesh renderer is attached to this GameObject, those will be used in the rasterization otherwise if a collider is attached, that will be used.

Public Member Functions

Bounds GetBounds ()
 Bounds completely enclosing the mesh for this object.
 
Collider GetCollider ()
 
MeshFilter GetMeshFilter ()
 

Static Public Member Functions

static void GetAllInBounds (List< RecastMeshObj > buffer, Bounds bounds)
 Fills the buffer with all RecastMeshObjs which intersect the specified bounds.
 

Public Attributes

int area = 0
 Voxel area for mesh.
 
Bounds bounds
 
bool dynamic = true
 Check if the object will move.
 

Static Protected Attributes

static List< RecastMeshObjdynamicMeshObjs = new List<RecastMeshObj>()
 Dynamic objects are stored in a list since it is costly to update the tree every time they move.
 
static RecastBBTree tree = new RecastBBTree()
 Static objects are stored in a tree for fast bounds lookups.
 

Private Member Functions

void OnDisable ()
 
void OnEnable ()
 
void RecalculateBounds ()
 Recalculates the internally stored bounds of the object.
 
void Register ()
 

Private Attributes

bool _dynamic
 
bool registered
 

Additional Inherited Members

- Protected Member Functions inherited from VersionedMonoBehaviour
virtual void Awake ()
 
virtual int OnUpgradeSerializedData (int version)
 Handle serialization backwards compatibility.
 

Member Function Documentation

static void GetAllInBounds ( List< RecastMeshObj buffer,
Bounds  bounds 
)
static

Fills the buffer with all RecastMeshObjs which intersect the specified bounds.

Bounds GetBounds ( )

Bounds completely enclosing the mesh for this object.

Collider GetCollider ( )
MeshFilter GetMeshFilter ( )
void OnDisable ( )
private
void OnEnable ( )
private
void RecalculateBounds ( )
private

Recalculates the internally stored bounds of the object.

void Register ( )
private

Member Data Documentation

bool _dynamic
private
int area = 0

Voxel area for mesh.

This area (not to be confused with pathfinding areas, this is only used when rasterizing meshes for the recast graph) field can be used to explicitly insert edges in the navmesh geometry or to make some parts of the mesh unwalkable. If the area is set to -1, it will be removed from the resulting navmesh. This is useful if you have some object that you want to be included in the rasterization, but you don't want to let the character walk on it.

When rasterizing the world and two objects with different area values are adjacent to each other, a split in the navmesh geometry will be added between them, characters will still be able to walk between them, but this can be useful when working with navmesh updates.

Navmesh updates which recalculate a whole tile (updatePhysics=True) are very slow So if there are special places which you know are going to be updated quite often, for example at a door opening (opened/closed door) you can use areas to create splits on the navmesh for easier updating using normal graph updates (updatePhysics=False). See the below video for more information.

Bounds bounds
bool dynamic = true

Check if the object will move.

Recalculation of bounding box trees is expensive so if this is true, the object will simply be stored in an array. Easier to move, but slower lookup, so use wisely. If you for some reason want to move it, but don't want it dynamic (maybe you will only move it veery seldom and have lots of similar objects so they would add overhead by being dynamic). You can enable and disable the component every time you move it. Disabling it will remove it from the bounding box tree and enabling it will add it to the bounding box tree again.

The object should never move unless being dynamic or disabling/enabling it as described above.

List<RecastMeshObj> dynamicMeshObjs = new List<RecastMeshObj>()
staticprotected

Dynamic objects are stored in a list since it is costly to update the tree every time they move.

bool registered
private
RecastBBTree tree = new RecastBBTree()
staticprotected

Static objects are stored in a tree for fast bounds lookups.


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