{"record":{"id":"97e6cca79ec43015","repo":"stride3d/stride","slug":"game-is-not-of-type-entityhierarchyeditorgame","errorCode":null,"errorMessage":"game is not of type EntityHierarchyEditorGame","messagePattern":"game is not of type EntityHierarchyEditorGame","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EditorGameNavigationMeshService.cs","lineNumber":176,"sourceCode":"                {\n                    displayGroup.IsVisible = isVisible;\n                    foreach (var component in debugVisuals)\n                    {\n                        ModelComponent modelComponent;\n                        if (component.Value.ModelComponents.TryGetValue(displayGroup.Id, out modelComponent))\n                        {\n                            modelComponent.Enabled = isVisible;\n                        }\n                    }\n                }\n            });\n        }\n\n        protected override async Task<bool> Initialize(EditorServiceGame editorGame)\n        {\n            if (editorGame == null) throw new ArgumentNullException(nameof(editorGame));\n            game = editorGame as SceneEditorGame;\n            if (game == null) throw new ArgumentException($\"{nameof(game)} is not of type {nameof(EntityHierarchyEditorGame)}\");\n\n            sceneEditorController = editor.Controller as SceneEditorController;\n            if (sceneEditorController == null) throw new ArgumentNullException(nameof(sceneEditorController));\n            \n            gameSettingsProviderService = editor.ServiceProvider.Get<GameSettingsProviderService>();\n            gameSettingsProviderService.GameSettingsChanged += GameSettingsProviderServiceOnGameSettingsChanged;\n            await navigationMeshManager.Initialize();\n\n            game.SceneAdded += GameOnSceneAdded;\n            game.SceneRemoved += GameOnSceneRemoved;\n\n            // Add debug entity\n            rootDebugEntity = new Entity(\"Navigation debug entity\");\n            game.EditorScene.Entities.Add(rootDebugEntity);\n\n            // Handle added/updated navigation meshes so that they can be made visible when this scene is shown\n            editor.Session.AssetPropertiesChanged += OnAssetPropertiesChanged;\n            editor.Session.DeletedAssetsChanged += OnDeletedAssetsChanged;","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EditorGameNavigationMeshService.cs#L158-L194","documentation":"EditorGameNavigationMeshService.Initialize casts the incoming EditorServiceGame to SceneEditorGame; if the cast fails (the game passed is not the entity-hierarchy editor game) an ArgumentException is thrown, since the navigation-mesh service only works with that concrete game type.","triggerScenarios":"Registering the navigation mesh editor service with an EditorServiceGame instance that is not a SceneEditorGame/EntityHierarchyEditorGame; passing null-adjacent wrong game during editor service initialization.","commonSituations":"Hosting the navmesh service in a custom editor game class; constructing editor services manually with the wrong game; copy-pasted editor bootstrap code using a base EditorServiceGame.","solutions":["Ensure the game passed to editor services is an EntityHierarchyEditorGame (or SceneEditorGame)","Do not register EditorGameNavigationMeshService in a plain EditorServiceGame host","Check the service registration/bootstrap code to confirm which game instance is created first","Verify no custom subclass shadows the expected game type"],"exampleFix":"// before\nvar game = new EditorServiceGame(services);\nnavMeshService.Initialize(game);\n// after\nvar game = new EntityHierarchyEditorGame(services);\nnavMeshService.Initialize(game);","handlingStrategy":"type-guard","validationCode":"if (editorGame is SceneEditorGame sceneGame) { /* safe to init navmesh service */ }","typeGuard":"static bool SupportsNavMesh(EditorServiceGame g) => g is SceneEditorGame;","tryCatchPattern":"try { await service.Initialize(game); }\ncatch (ArgumentException ex) { log.Error(ex); /* use a non-navmesh fallback */ }","preventionTips":["Register navmesh service only with EntityHierarchyEditorGame hosts","Assert the game type in editor bootstrap before initializing services","Avoid subclassing EditorServiceGame for scene editing scenarios"],"tags":["csharp","editor","navmesh","type-cast"],"backgroundTag":"type-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}