{"record":{"id":"2fe255c47c47a05f","repo":"BabylonJS/Babylon.js","slug":"function-not-injected-yet-use-the-factory-to-crea","errorCode":null,"errorMessage":"Function not injected yet. Use the factory to create the plugin.","messagePattern":"Function not injected yet\\. Use the factory to create the plugin\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/addons/src/navigation/plugin/RecastNavigationJSPlugin.ts","lineNumber":191,"sourceCode":"\n    /**\n     * Get the time factor used for crowd agent update\n     * @returns the time factor\n     */\n    public get timeFactor(): number {\n        return this._timeFactor;\n    }\n\n    /**\n     * Creates a navigation mesh - will be injected by the factory\n     * @param meshes array of all the geometry used to compute the navigation mesh\n     * @param parameters bunch of parameters used to filter geometry\n     * @returns the created navmesh and navmesh query\n     * @throws Error if the function is not injected yet or if the navmesh is not created\n     */\n    public createNavMesh(meshes: Array<Mesh>, parameters: INavMeshParametersV2): CreateNavMeshResult {\n        if (!this.createNavMeshImpl) {\n            throw new Error(\"Function not injected yet. Use the factory to create the plugin.\");\n        }\n\n        this._preprocessParameters(parameters);\n\n        const result = this.createNavMeshImpl(meshes, parameters);\n        return this._processNavMeshResult(result);\n    }\n\n    /**\n     * Creates a navigation mesh asynchronously - will be injected by the factory\n     * @param meshes array of all the geometry used to compute the navigation mesh\n     * @param parameters bunch of parameters used to filter geometry\n     * @returns the created navmesh and navmesh query\n     * @throws Error if the function is not injected yet or if the navmesh is not created\n     */\n    public async createNavMeshAsync(meshes: Array<Mesh>, parameters: INavMeshParametersV2): Promise<CreateNavMeshResult> {\n        if (!this.createNavMeshAsyncImpl) {\n            throw new Error(\"Function not injected yet. Use the factory to create the plugin.\");","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/addons/src/navigation/plugin/RecastNavigationJSPlugin.ts#L173-L209","documentation":"RecastNavigationJSPluginV2.createNavMesh (RecastNavigationJSPlugin.ts:191) throws this when createNavMeshImpl is undefined. The plugin class deliberately ships with no generator implementation; the factory functions (CreateNavigationPluginAsync, etc.) construct the plugin and inject the generator functions. Calling createNavMesh on a plugin you constructed yourself with `new RecastNavigationJSPluginV2()` (without a RecastInjection, which triggers GetRecast/InjectGenerators, or before initialization completed) leaves the impl unassigned and the call fails.","triggerScenarios":"Instantiating the plugin directly via `new RecastNavigationJSPluginV2()` and then calling createNavMesh, instead of using CreateNavigationPluginAsync()/CreateNavigationPluginWorkerAsync(); or calling createNavMesh before the async factory's promise resolved; or constructing with `new RecastNavigationJSPluginV2(customInjection)` where the injection did not run InjectGenerators. Note the worker-mode plugin overrides createNavMesh to warn and return null, so this throw mainly applies to manually constructed plugins.","commonSituations":"Migrating from the old RecastJSPlugin where direct construction was normal; forgetting to await the factory; bundler tree-shaking the factory module; calling the sync method on a worker-mode plugin mindset.","solutions":["Create the plugin through the factory: `const plugin = await CreateNavigationPluginAsync();` instead of `new RecastNavigationJSPluginV2()`.","Ensure the factory promise is awaited before any createNavMesh call.","If you must construct manually, pass a proper RecastInjection (so GetRecast + InjectGenerators run) and confirm recast wasm is initialized first (await init()).","In worker mode, use createNavMeshAsync — sync createNavMesh is intentionally disabled there."],"exampleFix":"// before\nconst plugin = new RecastNavigationJSPluginV2();\nplugin.createNavMesh(meshes, params); // throws: impl not injected\n\n// after\nconst plugin = await CreateNavigationPluginAsync();\nplugin.createNavMesh(meshes, params);","handlingStrategy":"validation","validationCode":"// Run BEFORE calling createNavMesh\nif (!plugin.createNavMeshImpl) {\n    throw new Error(\"Plugin not created via factory. Use: const plugin = await CreateNavigationPluginAsync()\");\n}","typeGuard":"function isFactoryCreated(plugin: RecastNavigationJSPluginV2): boolean {\n    return typeof plugin.createNavMeshImpl === \"function\";\n}","tryCatchPattern":"try {\n    plugin.createNavMesh(meshes, params);\n} catch (e) {\n    if (e instanceof Error && e.message.includes(\"Function not injected yet\")) {\n        throw new Error(\"Construct the plugin with CreateNavigationPluginAsync(), not `new RecastNavigationJSPluginV2()`\");\n    }\n    throw e;\n}","preventionTips":["Never construct RecastNavigationJSPluginV2 directly; always use CreateNavigationPluginAsync()/CreateNavigationPluginWorkerAsync().","Await the factory promise before calling any plugin method.","When migrating from the legacy RecastJSPlugin, replace direct `new` construction with the factory.","In worker mode, call createNavMeshAsync instead of createNavMesh."],"tags":["navigation","initialization-order","factory","recast","dependency-injection"],"backgroundTag":"plugin-not-initialized","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}