{"record":{"id":"fc08bbfedf30d02c","repo":"Unity-Technologies/ml-agents","slug":"demonstration-import-error","errorCode":null,"errorMessage":"Demonstration import error.","messagePattern":"Demonstration import error\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Editor/DemonstrationImporter.cs","lineNumber":29,"sourceCode":"#endif\nusing Unity.MLAgents.Demonstrations;\n\nnamespace Unity.MLAgents.Editor\n{\n    /// <summary>\n    /// Asset Importer used to parse demonstration files.\n    /// </summary>\n    [ScriptedImporter(1, new[] { \"demo\" })]\n    internal class DemonstrationImporter : ScriptedImporter\n    {\n        const string k_IconPath = \"Packages/com.unity.ml-agents/Editor/Icons/DemoIcon.png\";\n\n        public override void OnImportAsset(AssetImportContext ctx)\n        {\n            var inputType = Path.GetExtension(ctx.assetPath);\n            if (inputType == null)\n            {\n                throw new Exception(\"Demonstration import error.\");\n            }\n\n            try\n            {\n                // Read first three proto objects containing metadata, brain parameters, and observations.\n                Stream reader = File.OpenRead(ctx.assetPath);\n\n                var metaDataProto = DemonstrationMetaProto.Parser.ParseDelimitedFrom(reader);\n                var metaData = metaDataProto.ToDemonstrationMetaData();\n\n                reader.Seek(DemonstrationWriter.MetaDataBytes + 1, 0);\n                var brainParamsProto = BrainParametersProto.Parser.ParseDelimitedFrom(reader);\n                var brainParameters = brainParamsProto.ToBrainParameters();\n\n                // Read the first AgentInfoActionPair so that we can get the observation sizes.\n                List<ObservationSummary> observationSummaries;\n                try\n                {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Editor/DemonstrationImporter.cs#L11-L47","documentation":"Thrown by DemonstrationImporter.OnImportAsset when Unity imports a .demo asset whose path extension resolves to null. The importer inspects Path.GetExtension(ctx.assetPath) and treats a null extension as an unrecoverable input problem, aborting the import with a generic Exception. In practice GetExtension almost never returns null, so this is effectively a defensive guard against malformed import contexts.","triggerScenarios":"Unity's asset import pipeline invokes OnImportAsset with a ctx whose assetPath yields Path.GetExtension() == null (path with no parseable extension). This only fires before the try block that reads the demonstration proto.","commonSituations":"Importing a .demo file that was renamed to have no extension, or a corrupted/odd asset path reaching the importer; rarely seen because Unity normally only routes files with recognized extensions to this importer.","solutions":["Verify the imported asset file has a valid extension, ideally '.demo'","Re-import by placing the demonstration file with its original '.demo' extension in the project","Re-export the demonstration from the training environment if the asset is corrupted"],"exampleFix":"// before\nFile.WriteAllText(\"Assets/myDemo\", demoJson);\n// after\nFile.WriteAllText(\"Assets/myDemo.demo\", demoJson);","handlingStrategy":"validation","validationCode":"if (Path.GetExtension(assetPath) == null || !assetPath.EndsWith(\".demo\")) {\n    Debug.LogError($\"Invalid demonstration asset path: {assetPath}\");\n    return;\n}","typeGuard":"bool IsValidDemoPath(string path) => path != null && path.EndsWith(\".demo\");","tryCatchPattern":null,"preventionTips":["Always keep the .demo extension on demonstration files","Don't rename demo assets to extensionless names","Re-export demos if a file appears corrupted"],"tags":["unity","editor","asset-import","demonstration"],"backgroundTag":"asset-import-failed","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}