Search Issue Tracker

Fixed in 2019.3.X

Votes

0

Found in

2019.3.0a1

2019.3.0a2

Issue ID

1161227

Regression

Yes

Crash on AssetDatabase::ReserializePrefabs when attempting to save a prefab at the same path as an existing folder (via Script)

Asset - Database

-

How to reproduce:
1. Open attached project (Bug.zip)
2. Navigate to Test>Absolute Evil
3. Press Cancel

Reproducible with: 2019.3.0a1 2019.3.0a6
Not reproducible with: 2017.4.29f1, 2018.4.2f1, 2019.1.7f1, 2019.2.0b6

----
UPDATE:

The code that triggers the problem:
public static void SavePrefab1()
{
var path = "Assets/folder.prefab";
Directory.CreateDirectory(path);
PrefabUtility.SaveAsPrefabAsset(new GameObject(), path); //<- This causes save prefab to crash when the user clicks "Cancel" in the dialog that pops up
}

An alternative that handles the existence of files/directories:
public static void SavePrefab2()
{
var path = "Assets/folder.prefab";
Directory.CreateDirectory(path);

if (File.Exists(path))
{
if (EditorUtility.DisplayDialog("Saving new prefab", "There is already an asset at path '" + path + "', do you want to replace it?", "Yes", "No"))
{
File.Delete(path);
}
else
{
return;
}
}

if (Directory.Exists(path))
{
if (EditorUtility.DisplayDialog("Saving new prefab", "There is already a directory at path '" + path + "', do you want to replace it?", "Yes", "No"))
{
Directory.Delete(path, true);
}
else
{
return;
}
}

PrefabUtility.SaveAsPrefabAsset(new GameObject(), path);
}

This alternative is to be considered a workaround for now; the correct behavior is not defined at this point.

Fixed in: 2019.3.0a11

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.