Unity-Technologies/ml-agents · error · Exception

Demonstration import error.

Error message

Demonstration import error.

What it means

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.

Source

Thrown at com.unity.ml-agents/Editor/DemonstrationImporter.cs:29

#endif
using Unity.MLAgents.Demonstrations;

namespace Unity.MLAgents.Editor
{
    /// <summary>
    /// Asset Importer used to parse demonstration files.
    /// </summary>
    [ScriptedImporter(1, new[] { "demo" })]
    internal class DemonstrationImporter : ScriptedImporter
    {
        const string k_IconPath = "Packages/com.unity.ml-agents/Editor/Icons/DemoIcon.png";

        public override void OnImportAsset(AssetImportContext ctx)
        {
            var inputType = Path.GetExtension(ctx.assetPath);
            if (inputType == null)
            {
                throw new Exception("Demonstration import error.");
            }

            try
            {
                // Read first three proto objects containing metadata, brain parameters, and observations.
                Stream reader = File.OpenRead(ctx.assetPath);

                var metaDataProto = DemonstrationMetaProto.Parser.ParseDelimitedFrom(reader);
                var metaData = metaDataProto.ToDemonstrationMetaData();

                reader.Seek(DemonstrationWriter.MetaDataBytes + 1, 0);
                var brainParamsProto = BrainParametersProto.Parser.ParseDelimitedFrom(reader);
                var brainParameters = brainParamsProto.ToBrainParameters();

                // Read the first AgentInfoActionPair so that we can get the observation sizes.
                List<ObservationSummary> observationSummaries;
                try
                {

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Verify the imported asset file has a valid extension, ideally '.demo'
  2. Re-import by placing the demonstration file with its original '.demo' extension in the project
  3. Re-export the demonstration from the training environment if the asset is corrupted

Example fix

// before
File.WriteAllText("Assets/myDemo", demoJson);
// after
File.WriteAllText("Assets/myDemo.demo", demoJson);
Defensive patterns

Strategy: validation

Validate before calling

if (Path.GetExtension(assetPath) == null || !assetPath.EndsWith(".demo")) {
    Debug.LogError($"Invalid demonstration asset path: {assetPath}");
    return;
}

Type guard

bool IsValidDemoPath(string path) => path != null && path.EndsWith(".demo");

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02). Data as JSON: /api/errors/fc08bbfedf30d02c. Report an issue: GitHub.