{"record":{"id":"3e75db0a408ae6f6","repo":"Unity-Technologies/UnityCsReference","slug":"unable-to-add-sourcefile-to-streamingassets-a","errorCode":null,"errorMessage":"Unable to add '{sourceFile}' to StreamingAssets. An entry for '{targetPath}' has already been added, '{existingValue}'.","messagePattern":"Unable to add '(.+?)' to StreamingAssets\\. An entry for '(.+?)' has already been added, '(.+?)'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/BuildPipeline/BuildPlayerContext.cs","lineNumber":108,"sourceCode":"                NPath targetPath = pathInStreamingAssets ?? sourcePath.FileName;\n                AddAdditionalFileToStreamingAssets(sourcePath, targetPath);\n            }\n            else\n            {\n                throw new FileNotFoundException(\"No such file or directory.\", sourcePath.ToString());\n            }\n        }\n\n        private void AddAdditionalFileToStreamingAssets(NPath sourceFile, NPath targetPath)\n        {\n            if (StreamingAssetFiles.TryGetValue(targetPath, out var existingValue))\n            {\n                // If someone is adding the same file more than once we ignore subsequent adds\n                if (existingValue == sourceFile)\n                    return;\n\n                // Throw an exception and tell the user what the problem is\n                throw new ArgumentException(\n                    $\"Unable to add '{sourceFile}' to StreamingAssets. An entry for '{targetPath}' has already been added, '{existingValue}'.\");\n            }\n            StreamingAssetFiles.Add(targetPath, sourceFile);\n        }\n    }\n}\n","sourceCodeStart":90,"sourceCodeEnd":115,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/BuildPipeline/BuildPlayerContext.cs#L90-L115","documentation":"Thrown by BuildPlayerContext.AddAdditionalFileToStreamingAssets when a file is added for a targetPath that already has a different source file registered. The StreamingAssetFiles dictionary maps target paths to source files; a second registration under the same target with a different source is treated as a conflict. Adding the identical file twice is silently ignored.","triggerScenarios":"Two calls to AddAdditionalFileToStreamingAssets that map different source files to the same target path inside StreamingAssets — e.g., adding 'config/local.json' and 'prod/config.json' both as 'config.json'.","commonSituations":"Multiple build processors or plugins each adding files to StreamingAssets without coordinating target paths, a loop that adds files with a fixed target name, or two features both wanting 'settings.json' at the StreamingAssets root.","solutions":["Ensure each targetPath is unique across all AddAdditionalFileToStreamingAssets calls — namespace by feature or subfolder if needed.","If two sources legitimately need the same name, place them in different subdirectories under StreamingAssets.","Audit all AddAdditionalFileToStreamingAssets callers (including third-party plugins) to find the conflicting registration."],"exampleFix":"// before\ncontext.AddAdditionalFileToStreamingAssets(\"config/dev.json\", \"settings.json\");\ncontext.AddAdditionalFileToStreamingAssets(\"config/prod.json\", \"settings.json\"); // conflict!\n\n// after\ncontext.AddAdditionalFileToStreamingAssets(\"config/dev.json\", \"dev/settings.json\");\ncontext.AddAdditionalFileToStreamingAssets(\"config/prod.json\", \"prod/settings.json\");","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> s_registeredTargets = new();\n\nvoid AddToStreamingAssetsUnique(BuildPlayerContext ctx, string sourcePath, string targetPath)\n{\n    if (s_registeredTargets.Contains(targetPath))\n        throw new ArgumentException(\n            $\"Duplicate StreamingAssets target '{targetPath}'. Use a unique subfolder.\");\n    s_registeredTargets.Add(targetPath);\n    ctx.AddAdditionalFileToStreamingAssets(sourcePath, targetPath);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Namespace StreamingAssets target paths by feature or plugin to avoid collisions.","Maintain a registry of registered target paths and check before adding.","Coordinate between multiple build processors that add files to StreamingAssets."],"tags":["unity","build-pipeline","streaming-assets","path-conflict","buildplayer-context"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}