You’re actually going to want to call OnValidate regardless of whether there are existing nodes, since OnValidate is where we build the Dictionary.
A couple changes, though, to make sure that you can run your project after it’s been built. It turns out that OnValidate is never called in a built game (because it’s generally called when editing). For this reason, we need to make sure that OnValidate is called in Awake even when it’s not editor…
Make sure that OnValidate() is not in an #if UNITY EDITOR block.
Then make Awake look like this:
private void Awake()
{
#if UNITY_EDITOR
if (nodes.Count == 0)
{
nodes.Add(new DialogueNode());
}
#endif
OnValidate();
}
Later in the section, we’ll be changing the way we add that default node. When that happens, Sam will be deleting the Awake() method to cover the OnBeforeSerialize method.
In this case, rather than deleting Awake(), just delete the section in the editor block. Then Awake will be simply
private void Awake()
{
OnValidate();
}