{"record":{"id":"fcdc87f90b4e153c","repo":"Unity-Technologies/UnityCsReference","slug":"templatepath","errorCode":null,"errorMessage":"templatePath","messagePattern":"templatePath","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/ProjectBrowser/ProjectWindowUtil.cs","lineNumber":749,"sourceCode":"            var action = ScriptableObject.CreateInstance<DoCreateAssetWithContent>();\n            action.filecontent = content;\n            action.onComplete = onRenameComplete != null ? (id) => onRenameComplete(id) : null; // Wrap to obsolete int version\n            StartNameEditingIfProjectWindowExists(EntityId.None, action, filename, icon, null);\n        }\n\n        public static void CreateAssetWithTextContent(string filename, string content, Texture2D icon = null, Action<EntityId> onRenameComplete = null)\n        {\n            var action = ScriptableObject.CreateInstance<DoCreateAssetWithContent>();\n            action.filecontent = content;\n            action.onComplete = onRenameComplete;\n            StartNameEditingIfProjectWindowExists(EntityId.None, action, filename, icon, null);\n        }\n\n        [RequiredByNativeCode]\n        public static void CreateScriptAssetFromTemplateFile(string templatePath, string defaultNewFileName)\n        {\n            if (templatePath == null)\n                throw new ArgumentNullException(nameof(templatePath));\n            if (!File.Exists(templatePath))\n                throw new FileNotFoundException($\"The template file \\\"{templatePath}\\\" could not be found.\", templatePath);\n\n            if (string.IsNullOrEmpty(defaultNewFileName))\n                defaultNewFileName = Path.GetFileName(templatePath);\n\n            Texture2D icon = null;\n            switch (Path.GetExtension(defaultNewFileName))\n            {\n                case \".cs\":\n                    icon = EditorGUIUtility.IconContent(\"cs Script Icon\").image as Texture2D;\n                    break;\n                case \".shader\":\n                    icon = EditorGUIUtility.IconContent<Shader>().image as Texture2D;\n                    break;\n                case \".asmdef\":\n                    icon = EditorGUIUtility.IconContent<AssemblyDefinitionAsset>().image as Texture2D;\n                    break;","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/ProjectBrowser/ProjectWindowUtil.cs#L731-L767","documentation":"ProjectWindowUtil.CreateScriptAssetFromTemplateFile throws an ArgumentNullException when templatePath is null. This method creates a new script asset from a template file (e.g., creating a new MonoBehaviour or Shader via menu), and requires a valid path to the template.","triggerScenarios":"Calling ProjectWindowUtil.CreateScriptAssetFromTemplateFile(null, defaultName) where the template path argument is null.","commonSituations":"Custom menu items that create scripts from templates but pass a null path due to a misconfigured template location, or when the template path comes from a ScriptableObject field that was left empty. Also happens when template files are expected in a package but the package isn't installed.","solutions":["Pass a valid template path, typically under the Unity editor templates folder or a package path.","Validate templatePath != null before calling.","If referencing a package template, ensure the package is installed and the path is correct (e.g., 'Packages/com.unity.terrain-tools/Editor/Templates/...').","Use EditorGUIUtility.isProSkin or EditorApplication.applicationPath to construct template paths robustly."],"exampleFix":"// before\nProjectWindowUtil.CreateScriptAssetFromTemplateFile(null, \"NewBehaviourScript.cs\");\n// after\nvar templatePath = \"Assets/Editor/Templates/C# Script-NewBehaviourScript.cs.txt\";\nif (templatePath != null && File.Exists(templatePath))\n    ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, \"NewBehaviourScript.cs\");","handlingStrategy":"validation","validationCode":"if (templatePath != null)\n    ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, defaultName);","typeGuard":"static bool IsValidTemplatePath(string path) => path != null && File.Exists(path);","tryCatchPattern":null,"preventionTips":["Hardcode or validate template paths in custom menu items","Use AssetDatabase.FindAssets to locate template files dynamically","Store template paths in configuration rather than ad-hoc string construction"],"tags":["unity","editor","script-template","argument-null"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}