A word of warning on changing script execution order, which we do a lot of in this course. It’s important whenever we change the execution order, to make sure that we don’t wind up creating new issues. For example, you might move script A to execute before script B, and B to execute before script C but later have an issue where script A actually relies on something in script C…
In many cases these issues can be resolved with a few simple rules:
- Awake() => Cache references (this would include building your array of BaseActions). Do not act on any external reference here, except that you may subscribe to events here. Initialize variables that do not depend on external references here.
- OnEnable/OnDisable() => Subscribe and unsubscribe to events here, unless you subscribed in Awake()
- Start(), Update() => You should now be free to act on external references.
This isn’t to say never fiddle with the execution order (as I said, we do it in a couple of places in this course, and Hugo was mindful of the risks when he set them), but always be mindful of what depends on what so you don’t wind up just passing the race condition around to the next script.