{"record":{"id":"074568416ea72ac1","repo":"Unity-Technologies/UnityCsReference","slug":"can-t-connect-a-prefab-in-the-streamingassets-fold","errorCode":null,"errorMessage":"Can't connect a Prefab in the StreamingAssets folder to GameObjects in the scene. To save a Prefab to the StreamingAssets folder use SaveAsPrefabAsset instead.","messagePattern":"Can't connect a Prefab in the StreamingAssets folder to GameObjects in the scene\\. To save a Prefab to the StreamingAssets folder use SaveAsPrefabAsset instead\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2131,"sourceCode":"\n        public static GameObject SaveAsPrefabAsset(GameObject instanceRoot, string assetPath)\n        {\n            bool success;\n            return SaveAsPrefabAsset(instanceRoot, assetPath, out success);\n        }\n\n        public static GameObject SaveAsPrefabAssetAndConnect(GameObject instanceRoot, string assetPath, InteractionMode action)\n        {\n            bool success;\n            return SaveAsPrefabAssetAndConnect(instanceRoot, assetPath, action, out success);\n        }\n\n        public static GameObject SaveAsPrefabAssetAndConnect(GameObject instanceRoot, string assetPath, InteractionMode action, out bool success)\n        {\n            SaveAsPrefabAssetArgumentCheck(instanceRoot, assetPath, true);\n\n            if (IsPathInStreamingAssets(assetPath))\n                throw new ArgumentException(\"Can't connect a Prefab in the StreamingAssets folder to GameObjects in the scene. To save a Prefab to the StreamingAssets folder use SaveAsPrefabAsset instead.\");\n\n            var actionName = \"Connect to Prefab\";\n\n            if (action == InteractionMode.UserAction)\n            {\n                Undo.RegisterFullObjectHierarchyUndo(instanceRoot, actionName);\n            }\n\n            var assetRoot = SaveAsPrefabAssetAndConnect_Internal(instanceRoot, assetPath, out success);\n\n            if (!success)\n            {\n                return null;\n            }\n\n            if (action == InteractionMode.UserAction)\n            {\n                Undo.RecordCreatedObject(GetPrefabInstanceHandle(instanceRoot), actionName);","sourceCodeStart":2113,"sourceCodeEnd":2149,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2113-L2149","documentation":"Thrown by SaveAsPrefabAssetAndConnect when the target assetPath is inside the StreamingAssets folder. StreamingAssets are shipped read-only and cannot be connected to scene instances; connecting requires a standard asset folder. Unity directs the developer to use SaveAsPrefabAsset (without connect) for that location.","triggerScenarios":"Calling SaveAsPrefabAssetAndConnect with an assetPath that begins under the project's StreamingAssets directory (IsPathInStreamingAssets returns true).","commonSituations":"Developer wants to store a Prefab in StreamingAssets for runtime streaming and inadvertently uses the connect variant. Confusion about which StreamingAssets restrictions apply.","solutions":["Use SaveAsPrefabAsset (no connect) instead of SaveAsPrefabAssetAndConnect for StreamingAssets paths.","If you need a connectable Prefab, save it under Assets/ and copy to StreamingAssets separately if runtime streaming is required.","Check IsPathInStreamingAssets(assetPath) before deciding which API to call."],"exampleFix":"// before\nPrefabUtility.SaveAsPrefabAssetAndConnect(go,\n    \"Assets/StreamingAssets/x.prefab\", InteractionMode.AutomatedAction);\n// after\nPrefabUtility.SaveAsPrefabAsset(go,\n    \"Assets/StreamingAssets/x.prefab\");","handlingStrategy":"validation","validationCode":"void SavePrefabSmart(GameObject go, string path, bool connect)\n{\n    bool inStreaming = path.Contains(\"StreamingAssets\");\n    if (connect && inStreaming)\n    {\n        Debug.LogWarning(\"StreamingAssets path; using SaveAsPrefabAsset.\");\n        PrefabUtility.SaveAsPrefabAsset(go, path);\n    }\n    else if (connect)\n        PrefabUtility.SaveAsPrefabAssetAndConnect(go, path, InteractionMode.AutomatedAction);\n    else\n        PrefabUtility.SaveAsPrefabAsset(go, path);\n}","typeGuard":"static bool IsConnectablePath(string path) =>\n    !string.IsNullOrEmpty(path) && !path.Contains(\"StreamingAssets\");","tryCatchPattern":null,"preventionTips":["Never use the connect variant for StreamingAssets paths.","Centralize Prefab save API selection behind a helper.","Document StreamingAssets restrictions for your team."],"tags":["unity","prefab","streaming-assets","path-validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}