Purpose of this code inside OnValidate/OnAwake

So I noticed OnAwake doesn’t work for me just like others have noted. I followed the advice to use OnValidate but OnValidate only runs in a limited set of circumstances (such as domain reloads or edits in inspector UI).

And so it doesn’t reliably check if the node list is not empty. I created multiple objects that have 0 nodes. The only thing it reliably does is that it doesn’t let me delete the first (or 0th) node in the list but only once I already have one.

I’m curious what was the purpose of this exercise. I learned how to check the consistency of entries in the inspector which is something I was genuinely interested in. But it seems Sam was trying to teach us something else.

Awake() should be firing when the Dialogue is first created, which is when the node would be created. (We’re actually going to change this later use an OnBeforeSerialize interface method instead.

There is, however, a new bug which was introduced when Unity pushed their asset management code to using the Jobs system…
Step 1: The Dialogue is created, OnAwake() fires, creating the new node.
Step 2: The Dialogue in this new created state still does not have a name (you’re in rename state), once you commit a name
Step 3: The Dialogue is re-created as a new object with the new name, but Awake() is NOT called, leaving you with no Dialogue node.

Later in the course, when we move the logic to build the lookup dictionary to OnValidate(), you get a very annoying error which due to parallel code (Jobs), even null checking won’t block the null reference.

In short, the code presented here did work, right up until Unity pulled the rug out from under developers and made the Editor’s serialization system use Jobs.

Ok thanks. I’m about to get to that part. I’m past the part where the lookup table Dictionary is being used. I created a separate RebuildDictionary method that is called by Awake and OnValidate expecting that might be useful.

While it is a bummer this one lecture is no longer serving the intended purpose, I learned and practiced other useful stuff. The video could use a bit of an interjected update mid-stream to let students know that the code wont work and that a practical application of this is coming in later lectures.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms