{"record":{"id":"db3bd596340b3a83","repo":"Unity-Technologies/UnityCsReference","slug":"the-template-file-templatepath-could-not-be-fo","errorCode":null,"errorMessage":"The template file \"{templatePath}\" could not be found.","messagePattern":"The template file \"(.+?)\" could not be found\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/ProjectBrowser/ProjectWindowUtil.cs","lineNumber":751,"sourceCode":"            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;\n                case \".asmref\":\n                    icon = EditorGUIUtility.IconContent<AssemblyDefinitionReferenceAsset>().image as Texture2D;","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/ProjectBrowser/ProjectWindowUtil.cs#L733-L769","documentation":"ProjectWindowUtil.CreateScriptAssetFromTemplateFile throws a FileNotFoundException when the template file at templatePath does not exist on disk. The method verifies File.Exists(templatePath) before proceeding with script generation.","triggerScenarios":"Calling CreateScriptAssetFromTemplateFile with a path to a template file that doesn't exist on the filesystem.","commonSituations":"Custom template files that were deleted or moved, package templates where the package was updated/removed, or hardcoded relative paths that resolve incorrectly depending on working directory. Common when upgrading Unity versions that changed template locations.","solutions":["Verify the file exists with File.Exists(templatePath) before calling.","Use absolute or AssetDatabase-relative paths rather than relative filesystem paths.","If using package templates, check the package is installed: PackageUtility.CheckForInvalidPath or Directory.Exists on the package folder.","For built-in templates, use the correct Unity version's template path."],"exampleFix":"// before\nProjectWindowUtil.CreateScriptAssetFromTemplateFile(\"Assets/Templates/Missing.cs.txt\", \"NewScript.cs\");\n// after\nvar templatePath = \"Assets/Editor/Templates/ScriptTemplate.cs.txt\";\nif (!File.Exists(templatePath))\n    Debug.LogError($\"Template not found: {templatePath}\");\nelse\n    ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, \"NewScript.cs\");","handlingStrategy":"validation","validationCode":"if (templatePath != null && File.Exists(templatePath))\n    ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, defaultName);\nelse\n    Debug.LogError($\"Template file not found: {templatePath}\");","typeGuard":"static bool TemplateExists(string path) => !string.IsNullOrEmpty(path) && File.Exists(path);","tryCatchPattern":null,"preventionTips":["Verify File.Exists on template paths before calling","Use absolute or project-relative paths consistently","Check that template-shipping packages are installed"],"tags":["unity","editor","script-template","file-not-found"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}