{"record":{"id":"23d1731c4168d8de","repo":"CoplayDev/unity-mcp","slug":"screenshotter-cannot-be-null","errorCode":null,"errorMessage":"Screenshotter cannot be null","messagePattern":"Screenshotter cannot be null","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/TypePreviewGeneratorFromScene.cs","lineNumber":29,"sourceCode":"namespace AssetStoreTools.Previews.Generators.Custom.TypeGenerators\r\n{\r\n    internal abstract class TypePreviewGeneratorFromScene : TypePreviewGeneratorBase\r\n    {\r\n        protected new TypePreviewGeneratorFromSceneSettings Settings;\r\n\r\n        private CancellationTokenSource _cancellationTokenSource;\r\n\r\n        public TypePreviewGeneratorFromScene(TypePreviewGeneratorFromSceneSettings settings) : base(settings)\r\n        {\r\n            Settings = settings;\r\n        }\r\n\r\n        public override void ValidateSettings()\r\n        {\r\n            base.ValidateSettings();\r\n\r\n            if (Settings.Screenshotter == null)\r\n                throw new ArgumentException(\"Screenshotter cannot be null\");\r\n        }\r\n\r\n        protected sealed override async Task<List<PreviewMetadata>> GenerateImpl(IEnumerable<UnityEngine.Object> assets)\r\n        {\r\n            var originalScenePath = EditorSceneManager.GetActiveScene().path;\r\n            await PreviewSceneUtility.OpenPreviewSceneForCurrentPipeline();\r\n\r\n            try\r\n            {\r\n                _cancellationTokenSource = new CancellationTokenSource();\r\n                EditorSceneManager.sceneOpened += SceneOpenedDuringGeneration;\r\n                return await GeneratePreviewsInScene(assets);\r\n            }\r\n            finally\r\n            {\r\n                EditorSceneManager.sceneOpened -= SceneOpenedDuringGeneration;\r\n                _cancellationTokenSource.Dispose();\r\n                if (!string.IsNullOrEmpty(originalScenePath))\r","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/TypePreviewGeneratorFromScene.cs#L11-L47","documentation":"Thrown by TypePreviewGeneratorFromScene.ValidateSettings when Settings.Screenshotter is null. The scene-based preview generator requires a screenshotter instance to capture previews of objects in a scene. This validation runs after the base class InputPaths/OutputPath checks.","triggerScenarios":"Calling Generate() or ValidateSettings() on a TypePreviewGeneratorFromScene with Settings.Screenshotter == null. The screenshotter is used in GeneratePreviewsInScene to capture each object.","commonSituations":"Settings constructed without assigning a Screenshotter; screenshotter field was cleared during settings reset; deserialized settings where the screenshotter (a non-serializable object reference) was not reconnected; UI didn't create the screenshotter before starting generation.","solutions":["Create and assign a screenshotter instance (e.g., a SceneScreenshotter subclass) to Settings.Screenshotter before calling Generate.","Initialize the screenshotter in a settings factory method alongside dimension validation.","If deserializing settings, reconstruct the screenshotter programmatically after load."],"exampleFix":"// before\nvar settings = new TypePreviewGeneratorFromSceneSettings { InputPaths = paths, OutputPath = outPath, Screenshotter = null };\nvar generator = new TypePreviewGeneratorFromScene(settings);\nawait generator.Generate();\n\n// after\nvar screenshotter = new SceneScreenshotter(screenshotSettings);\nvar settings = new TypePreviewGeneratorFromSceneSettings { InputPaths = paths, OutputPath = outPath, Screenshotter = screenshotter };\nvar generator = new TypePreviewGeneratorFromScene(settings);\nawait generator.Generate();","handlingStrategy":"validation","validationCode":"if (settings.Screenshotter == null)\n    settings.Screenshotter = new SceneScreenshotter(CreateDefaultScreenshotSettings());\n// or validate:\nif (settings.Screenshotter == null)\n    throw new InvalidOperationException(\"A Screenshotter instance must be assigned before generation.\");","typeGuard":"static bool HasValidScreenshotter(TypePreviewGeneratorFromSceneSettings s)\n    => s?.Screenshotter != null;","tryCatchPattern":"try\n{\n    await generator.Generate();\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Screenshotter cannot be null\"))\n{\n    settings.Screenshotter = new SceneScreenshotter(CreateDefaultScreenshotSettings());\n    await generator.Generate();\n}","preventionTips":["Construct the screenshotter in the same factory method that builds the settings.","Reconnect non-serializable references like Screenshotter after deserialization.","Validate Screenshotter assignment in the UI before allowing generation to start."],"tags":["unity","asset-store-tools","preview","validation","screenshot"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}