Just documenting a bug that was discovered by one of our students against this lecture. This should be patched soon, but I’m putting this message here to highlight the issue.
After implementing the changes in this lecture, if you create a new Dialogue in your assets, Unity will lock up and eventually crash with a Stack Overflow error which logs will show traces to line 61 of Dialogue.cs. DO NOT DO THIS or you will lose any other changes you’ve made to your project! Just take my word for it, the bug exists.
The offending line in CreateNode() is
Undo.RecordObject(this, "Added New Node");
The cause of this bug relates to when we first create the Dialogue. In OnBeforeSerialize, we have added a call to CreateNode() if the list of nodes is empty. The problem is that for that brief moment after we first create a dialogue until we name the file, there is no actual file. It doesn’t exist. A call to Undo.RecordObject(this) will fail because this isn’t on the disk yet.
The solution is simple… surround the Undo call with an if statement to check to make sure that the file actually exists.
if (AssetDatabase.GetAssetPath(this)!="")
{
Undo.RecordObject(this, "Added Dialogue Node");
}