{"record":{"id":"76543bdc3bff5a81","repo":"CoplayDev/unity-mcp","slug":"native-width-should-be-larger-than-0","errorCode":null,"errorMessage":"Native width should be larger than 0","messagePattern":"Native width should be larger than 0","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/Screenshotters/SceneScreenshotterBase.cs","lineNumber":48,"sourceCode":"#endif\r\n            }\r\n\r\n            return _camera;\r\n        }\r\n\r\n        public virtual void ValidateSettings()\r\n        {\r\n            if (Settings.Width <= 0)\r\n                throw new ArgumentException(\"Width should be larger than 0\");\r\n\r\n            if (Settings.Height <= 0)\r\n                throw new ArgumentException(\"Height should be larger than 0\");\r\n\r\n            if (Settings.Depth <= 0)\r\n                throw new ArgumentException(\"Depth should be larger than 0\");\r\n\r\n            if (Settings.NativeWidth <= 0)\r\n                throw new ArgumentException(\"Native width should be larger than 0\");\r\n\r\n            if (Settings.NativeHeight <= 0)\r\n                throw new ArgumentException(\"Native height should be larger than 0\");\r\n        }\r\n\r\n        public abstract void PositionCamera(GameObject target);\r\n\r\n        public string Screenshot(string outputPath)\r\n        {\r\n            ValidateSettings();\r\n\r\n            var texture = GraphicsUtility.GetTextureFromCamera(Camera, Settings.NativeWidth, Settings.NativeHeight, Settings.Depth);\r\n\r\n            if (Settings.Width < Settings.NativeWidth || Settings.Height < Settings.NativeHeight)\r\n                texture = GraphicsUtility.ResizeTexture(texture, Settings.Width, Settings.Height);\r\n\r\n            var extension = PreviewConvertUtility.ConvertExtension(Settings.Format);\r\n            var writtenPath = $\"{outputPath}.{extension}\";\r","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/Screenshotters/SceneScreenshotterBase.cs#L30-L66","documentation":"Thrown by SceneScreenshotterBase.ValidateSettings when Settings.NativeWidth is zero or negative. NativeWidth is the actual render resolution passed to GraphicsUtility.GetTextureFromCamera before optional downscaling to Width. Validation fires before the camera capture.","triggerScenarios":"Calling Screenshot(outputPath) or ValidateSettings() with Settings.NativeWidth <= 0. NativeWidth is passed to GetTextureFromCamera(Camera, NativeWidth, NativeHeight, Depth).","commonSituations":"Settings deserialized with a missing NativeWidth; settings object created with only Width/Height set but native dimensions left at default 0; mismatched config where native dimensions were cleared but output dimensions weren't.","solutions":["Set Settings.NativeWidth to a positive integer matching or exceeding Width before rendering.","Initialize NativeWidth and NativeHeight together with Width and Height in settings construction.","Apply a post-deserialization pass that sets NativeWidth = Width when not explicitly provided."],"exampleFix":"// before\nvar settings = new SceneScreenshotterSettings { Width = 1024, Height = 1024, Depth = 24, NativeWidth = 0, NativeHeight = 2048 };\n\n// after\nvar settings = new SceneScreenshotterSettings { Width = 1024, Height = 1024, Depth = 24, NativeWidth = 2048, NativeHeight = 2048 };","handlingStrategy":"validation","validationCode":"if (settings.NativeWidth <= 0)\n    settings.NativeWidth = settings.Width > 0 ? settings.Width : 1920;\n// or validate:\nif (settings.NativeWidth <= 0)\n    throw new InvalidOperationException(\"NativeWidth must be set to a positive value.\");","typeGuard":"static bool IsValidScreenshotDimensions(SceneScreenshotterSettings s)\n    => s.Width > 0 && s.Height > 0 && s.Depth > 0 && s.NativeWidth > 0 && s.NativeHeight > 0;","tryCatchPattern":"try\n{\n    screenshotter.Screenshot(outputPath);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Native width should be larger than 0\"))\n{\n    settings.NativeWidth = settings.Width;\n    screenshotter.Screenshot(outputPath);\n}","preventionTips":["Set NativeWidth at minimum to Width when supersampling is not needed.","Initialize native dimensions together with output dimensions.","Default NativeWidth to Width after deserialization if not explicitly set."],"tags":["unity","asset-store-tools","preview","validation","render-texture"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}