I recently upgraded my version of Unity 2021.1 and now when I call AssetDatabase.SaveAssets(), I get the error
[Worker0] Broken text PPtr in file(Assets/Game/Dialogue/Dialogue.asset). Local file identifier (1528208011795455128) doesn't exist!
I never had this error in the previous version of Unity. Everything still works but this error does popup in the console on the AseetDatabase.SaveAssets() call. It only occurs when I create a new node for my dialog system.
I added a button to my dialog editor than when clicked it calls AssetDatabase.SaveAssets() and this doesn't throw the error but I don't want this. I want to save whenever I add a new node.
public DialogueNode CreateNode(DialogueNode parent, Vector2 position)
{
var newNode = MakeNode(parent, position);
Undo.RegisterCreatedObjectUndo(newNode, "Create Dialogue Node");
Undo.RecordObject(this, "Add Dialogue Node");
AddNode(newNode);
return newNode;
}
private DialogueNode MakeNode(DialogueNode parent, Vector2 position)
{
DialogueNode newNode = CreateInstance<DialogueNode>();
newNode.name = Guid.NewGuid().ToString();
newNode.SetSize(140, 40);
if (parent != null)
{
parent.AddChild(newNode.name);
newNode.Parent = parent;
newNode.IsPlayerSpeaking = !parent.IsPlayerSpeaking;
newNode.SetPosition(parent.Rect.position newNodeOffset, Grid.GridSnapSize);
if (parent.Children.Count > 1)
parent.SetSize(new Rect(parent.Rect.x, parent.Rect.y, 150, 40));
}
else
{
newNode.SetPosition(position, Grid.GridSnapSize);
}
return newNode;
}
private void AddNode(DialogueNode newNode)
{
newNode.Text = "";
nodes.Add(newNode);
OnValidate();
Save();
}
private void Save() => AssetDatabase.SaveAssets();
public void CreateNew()
{
if (nameForNew == "")
return;
var newItem = ScriptableObject.CreateInstance<T>();
newItem.name = "New " typeof(T); //May not need
if (path == "")
path = "Assets/";
AssetDatabase.CreateAsset(newItem, path "\\" nameForNew ".asset");
AssetDatabase.SaveAssets();
nameForNew = "";
}
CodePudding user response:
I think you should try to rather explicitly use AssetDatabase.CreateAsset
for your new created asset.
- Makes more sense than saving all assets across the entire project
- your new asset doesn't have any save path yet so where would you expect unity to save it persistently?
You basically are creating and storing only a "virtual" instance of a ScriptableObjec without the according persistent asset ...
So I think what the error means is you are trying to save (= serialize) your base/parent node including the according child node references.
However, since you never create the actual assets these references can not be serialized and are valid only temporary.
CodePudding user response:
After many trial and error attempts and hours of debugging I was able to solve it.
EditorApplication.delayCall = AssetDatabase.SaveAssets;
Now whenever I call AssetDatabase.SaveAssets() from the Save() function, I no longer get these errors. It appears I have to wait for the inspector to be updated. With this method, the call to AssetDatabase.SaveAssets() will be delayed until the inspector has been refreshed.