{"record":{"id":"11020ea9de19724e","repo":"BabylonJS/Babylon.js","slug":"recast-is-not-initialized-please-call-initrecast","errorCode":null,"errorMessage":"Recast is not initialized. Please call InitRecast first.","messagePattern":"Recast is not initialized\\. Please call InitRecast first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/addons/src/navigation/factory/common.ts","lineNumber":13,"sourceCode":"import { _LoadScriptModuleAsync } from \"core/Misc/tools.internals\";\nimport { type Nullable } from \"core/types\";\n\nimport { type RecastInjection } from \"../types\";\n\n/**\n * Gets the RecastInjection instance (reference to the recast-navigation-js library).\n * @returns The RecastInjection instance\n * @throws Error if Recast is not initialized\n */\nexport function GetRecast(): RecastInjection {\n    if (!_Recast) {\n        throw new Error(\"Recast is not initialized. Please call InitRecast first.\");\n    }\n    return _Recast;\n}\n\n/**\n * Sets the RecastInjection instance (reference to the recast-navigation-js library).\n * @param recast The RecastInjection instance to set\n */\nexport function SetRecast(recast: RecastInjection) {\n    _Recast = recast;\n}\n\n/**\n * Reference to the recast-navigation-js library\n */\nlet _Recast: RecastInjection;\n\n/**","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/addons/src/navigation/factory/common.ts#L1-L31","documentation":"The navigation module keeps a module-level `_Recast` handle to the recast-navigation-js WASM library, set only by calling InitRecast (which loads the WASM). GetRecast throws when the handle is still unset, i.e. any navigation API is used before initialization.","triggerScenarios":"Calling GetRecast directly, or any navigation API that depends on it (RecastJSPlugin construction, navmesh creation/recast helpers, CreateDefaultTileCacheMeshProcess) without first calling `await InitRecast()` (or InitRecast with the appropriate WASM import).","commonSituations":"Forgetting the async init step when migrating from the old bundled RecastJSPlugin; using navigation code in a module that loads before the async InitRecast() promise resolves; building the WASM path incorrectly so init silently never ran.","solutions":["Call and await `InitRecast()` (imported from @babylonjs/core or the addons navigation module) before any other navigation API.","Gate all navigation usage on the init promise: `await recastInitPromise;` at app startup.","If init already exists, check that it succeeded and that the correct WASM build/import path was used."],"exampleFix":"// before\nconst plugin = new RecastJSPlugin(); // throws: Recast not initialized\n// after\nimport { InitRecast } from \"@babylonjs/addons\";\nawait InitRecast();\nconst plugin = new RecastJSPlugin();","handlingStrategy":"validation","validationCode":"let recastReady = false;\nasync function ensureRecast() {\n  if (!recastReady) { await InitRecast(); recastReady = true; }\n}\nawait ensureRecast(); // before any navigation API","typeGuard":"let recastInitialized = false;\nexport const isRecastInitialized = (): boolean => recastInitialized;\nif (!isRecastInitialized()) { /* block navigation usage */ }","tryCatchPattern":"try {\n  plugin = new RecastJSPlugin(scene);\n} catch (e) {\n  if (String(e).includes(\"InitRecast\")) {\n    await InitRecast();\n    plugin = new RecastJSPlugin(scene);\n  } else throw e;\n}","preventionTips":["Always `await InitRecast()` once at app startup before navigation code runs.","Keep a single shared init promise instead of multiple init calls.","Import navigation modules only after (or gated behind) initialization."],"tags":["navigation","recast","wasm","initialization-order","async"],"backgroundTag":"library-not-initialized","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}