我最近升级了我的 Unity 2021.1 版本,现在当我调用 AssetDatabase.SaveAssets() 时,我收到了错误
[Worker0] Broken text PPtr in file(Assets/Game/Dialogue/Dialogue.asset). Local file identifier (1528208011795455128) doesn't exist!
在以前的 Unity 版本中,我从未遇到过此错误。一切仍然有效,但此错误确实会在 AseetDatabase.SaveAssets() 调用的控制台中弹出。只有当我为我的对话系统创建一个新节点时才会发生这种情况。
我在对话框编辑器中添加了一个按钮,而不是单击它时调用 AssetDatabase.SaveAssets() ,这不会引发错误,但我不想要这个。每当我添加一个新节点时,我都想保存。
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 = "";
}