NavMeshAsset
Baked navigation mesh. Owns: - The serialized Detour blob (m_blob) — what gets written to disk and re-loaded on scene open. - A live dtNavMesh built from that blob (m_navMesh) — what queries run against. - A shared dtNavMeshQuery handle wrapping the nav mesh (m_query). - Debug-viz triangles (m_triangles) for editor overlay.
- Module
- AINavigation
- Header
#include "AINavigation/NavMeshAsset.h"- Namespace
Mowo
Memory ownership: the blob bytes are also passed to dtNavMesh::init (DT_TILE_FREE_DATA), so on Unload Detour frees them — we must NOT free m_blob ourselves once it's been handed off. The pre-handoff "rejected" path (init failure) does free.
Constructors
| Signature | Name | Description |
|---|---|---|
NavMeshAsset() = default | NavMeshAsset | |
~NavMeshAsset() override | ~NavMeshAsset |
Public functions
| Returns | Name | Description |
|---|---|---|
bool | Load | Asset interface |
void | Unload | |
bool | CreateGPU | |
bool | IsBaked | |
dtNavMesh* | GetNavMesh | |
dtNavMeshQuery* | GetNavMeshQuery | |
dtTileCache* | GetTileCache | |
bool | HasDynamicObstacles | |
const std::vector<NavMeshTriangle>& | GetTriangles | Debug viz |
Vec3 | GetBoundsMin | |
Vec3 | GetBoundsMax | |
const NavMeshBakeSettings& | GetBakeSettings | |
bool | SetFromBakedData | Population (called by NavMeshBuilder after a successful bake) Takes ownership of navData — the bytes are handed to dtNavMesh with DT_TILE_FREE_DATA so Detour owns them after this call. |
bool | SetFromTiledNavMesh | Tiled bake variant: takes a pre-built multi-tile dtNavMesh and adopts it. |
bool | SetFromTileCache | Dynamic-obstacle variant: adopts both the live dtNavMesh and the dtTileCache that owns the compressed-layer storage. |
void | Clear | Drop everything — frees query, nav mesh (Detour also frees the blob), debug triangles and the agent variants. |
void | SetAgentVariant | Navmeshes for the other agent types in the bake settings. |
Ref<NavMeshAsset> | GetAgentVariant | |
const std::vector<FNavAgentVariant>& | GetAgentVariants | |
std::string | AgentTypeName | The name of the agent type settings bakes for ("Default" when the scene lists none). |
void | SetAgentName | The agent type this mesh was baked for. |
std::string | GetAgentName | |
void | AppendDebugTris | Append more debug-viz tris to the existing buffer. |
bool | SaveToFile | Disk I/O (custom .navmesh blob — versioned magic + Detour bytes + bounds + debug tris). |
Function details
NavMeshAsset
NavMeshAsset() = default~NavMeshAsset
~NavMeshAsset() overrideLoad
bool Load(const std::string& path) overrideAsset interface
Unload
void Unload() overrideCreateGPU
bool CreateGPU(const GPUContext& ctx) overrideIsBaked
bool IsBaked() constGetNavMesh
dtNavMesh* GetNavMesh() constGetNavMeshQuery
dtNavMeshQuery* GetNavMeshQuery() constGetTileCache
dtTileCache* GetTileCache() constHasDynamicObstacles
bool HasDynamicObstacles() constGetTriangles
const std::vector<NavMeshTriangle>& GetTriangles() constDebug viz
GetBoundsMin
Vec3 GetBoundsMin() constGetBoundsMax
Vec3 GetBoundsMax() constGetBakeSettings
const NavMeshBakeSettings& GetBakeSettings() constSetFromBakedData
bool SetFromBakedData(unsigned char* navData, int navDataSize, std::vector<NavMeshTriangle> debugTris, Vec3 boundsMin, Vec3 boundsMax, NavMeshBakeSettings settings)Population (called by NavMeshBuilder after a successful bake) Takes ownership of navData — the bytes are handed to dtNavMesh with DT_TILE_FREE_DATA so Detour owns them after this call. Used by the solo-mesh bake (single tile).
SetFromTiledNavMesh
bool SetFromTiledNavMesh(dtNavMesh* navMesh, std::vector<NavMeshTriangle> debugTris, Vec3 boundsMin, Vec3 boundsMax, NavMeshBakeSettings settings)Tiled bake variant: takes a pre-built multi-tile dtNavMesh and adopts it. The mesh's tiles already carry DT_TILE_FREE_DATA, so dtFreeNavMesh in Clear/dtor releases them. Caller must not touch navMesh after this returns true (we own it).
SetFromTileCache
bool SetFromTileCache(dtNavMesh* navMesh, dtTileCache* tileCache, std::vector<NavMeshTriangle> debugTris, Vec3 boundsMin, Vec3 boundsMax, NavMeshBakeSettings settings)Dynamic-obstacle variant: adopts both the live dtNavMesh and the dtTileCache that owns the compressed-layer storage. NavAgentSystem ticks the cache each frame; NavMeshObstacleSystem talks to it when components are added / moved / destroyed. Caller must not touch either pointer after this returns true.
Clear
void Clear()Drop everything — frees query, nav mesh (Detour also frees the blob), debug triangles and the agent variants.
SetAgentVariant
void SetAgentVariant(const std::string& agentName, float agentRadius, Ref<NavMeshAsset> nav)Navmeshes for the other agent types in the bake settings. The primary is the active agent type; NavAgentSystem runs one crowd per variant.
GetAgentVariant
Ref<NavMeshAsset> GetAgentVariant(const std::string& agentName) constGetAgentVariants
const std::vector<FNavAgentVariant>& GetAgentVariants() constAgentTypeName
static std::string AgentTypeName(const NavMeshBakeSettings& settings)The name of the agent type settings bakes for ("Default" when the scene lists none).
SetAgentName
void SetAgentName(const std::string& name)The agent type this mesh was baked for. The .navmesh file does not carry the scene's agent list, so a loader that knows it names the mesh; otherwise it reads from the bake settings.
GetAgentName
std::string GetAgentName() constAppendDebugTris
void AppendDebugTris(std::vector<NavMeshTriangle> more)Append more debug-viz tris to the existing buffer. Used by partial rebakes that want to add the newly-baked tile tris on top of the asset's existing display set.
SaveToFile
bool SaveToFile(const std::string& vfsPath) constDisk I/O (custom .navmesh blob — versioned magic + Detour bytes + bounds + debug tris). VFS-friendly: same path the Asset system hands us in Load().