Why does Undo only work properly if done in the SO itself?

As stated in the title, why does the Undo have to be called in the DialogueNode SO for it to work? Im still a bit confused as to why the setters and getters helped because in my head, it basically is the same implementation as before except the fields in DialogueNode SO are no longer public.

Thanks in advance!

The Undo system needs to track what was modified in order to do it’s job and undo the changes. It’s structured by Unity to do this by recording the object which is making the changes.

In terms of the Getters and Setters and the fields becoming private instead of public, this is a core pillar of OOP design. Leaving a field public (specifically, leaving the ability to change the field public) can expose your class to unwanted (and sometimes difficult to debug) changes from other classes. By restricting the ability to modify a property to a setter, we can get the opportunity to validate changes, and in the case of our Editor code, to set up the Undo system.

Privacy & Terms