Unity-Technologies/UnityCsReference · error · ArgumentException
Can't connect a Prefab in the StreamingAssets folder to Game
Error message
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.
What it means
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.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2131
public static GameObject SaveAsPrefabAsset(GameObject instanceRoot, string assetPath)
{
bool success;
return SaveAsPrefabAsset(instanceRoot, assetPath, out success);
}
public static GameObject SaveAsPrefabAssetAndConnect(GameObject instanceRoot, string assetPath, InteractionMode action)
{
bool success;
return SaveAsPrefabAssetAndConnect(instanceRoot, assetPath, action, out success);
}
public static GameObject SaveAsPrefabAssetAndConnect(GameObject instanceRoot, string assetPath, InteractionMode action, out bool success)
{
SaveAsPrefabAssetArgumentCheck(instanceRoot, assetPath, true);
if (IsPathInStreamingAssets(assetPath))
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.");
var actionName = "Connect to Prefab";
if (action == InteractionMode.UserAction)
{
Undo.RegisterFullObjectHierarchyUndo(instanceRoot, actionName);
}
var assetRoot = SaveAsPrefabAssetAndConnect_Internal(instanceRoot, assetPath, out success);
if (!success)
{
return null;
}
if (action == InteractionMode.UserAction)
{
Undo.RecordCreatedObject(GetPrefabInstanceHandle(instanceRoot), actionName);View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
PrefabUtility.SaveAsPrefabAssetAndConnect(go,
"Assets/StreamingAssets/x.prefab", InteractionMode.AutomatedAction);
// after
PrefabUtility.SaveAsPrefabAsset(go,
"Assets/StreamingAssets/x.prefab"); Defensive patterns
Strategy: validation
Validate before calling
void SavePrefabSmart(GameObject go, string path, bool connect)
{
bool inStreaming = path.Contains("StreamingAssets");
if (connect && inStreaming)
{
Debug.LogWarning("StreamingAssets path; using SaveAsPrefabAsset.");
PrefabUtility.SaveAsPrefabAsset(go, path);
}
else if (connect)
PrefabUtility.SaveAsPrefabAssetAndConnect(go, path, InteractionMode.AutomatedAction);
else
PrefabUtility.SaveAsPrefabAsset(go, path);
} Type guard
static bool IsConnectablePath(string path) =>
!string.IsNullOrEmpty(path) && !path.Contains("StreamingAssets"); Prevention
- Never use the connect variant for StreamingAssets paths.
- Centralize Prefab save API selection behind a helper.
- Document StreamingAssets restrictions for your team.
When it happens
Trigger: Calling SaveAsPrefabAssetAndConnect with an assetPath that begins under the project's StreamingAssets directory (IsPathInStreamingAssets returns true).
Common situations: Developer wants to store a Prefab in StreamingAssets for runtime streaming and inadvertently uses the connect variant. Confusion about which StreamingAssets restrictions apply.
Related errors
- Overwriting a folder with an Asset is not allowed: '{path}'
- Saving Prefab to immutable folder is not allowed: '{path}'
- Given path does not exist: '{path}'
- Scene path "{0}" contains invalid directory separators.
- Invalid build path: '{buildPlayerOptions.locationPathName}'.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/074568416ea72ac1.
Report an issue: GitHub.