You can drag scripts to the Script Execution Order window

Not to incentivize it, but it’s possible.

Also, is there any way to search for an enum (KeyCode for example), without creating a custom drawer?

2 Likes

What do you mean? Wouldn’t an enum appear as a dropdown already, simply by virtue of it being an enum (namely you wouldn’t need to do anything more)?

Now that you brought that to the table, Has anyone encountered a problem where the only acceptable solution was to change the script execution order? I can’t come up with any scenario where this is the only real solution, not even when using multiple threads.

I haven’t, and I would argue that changing the script execution order to avoid race conditions only masks the underlying code issues, and can lead to unintended consequences (like I’ve seen a project completely broken in the editor because somebody moved a script ahead of a core Unity script.)

Ideally, it’s best to stick to SOLID principles whenever possible, and make sure that the right things happen in the right Unity callback methods.

  • Awake() → Cache component references. You can subscribe to events here if you are using the Awake/OnDestroy paradigm for subscriptions. Otherwise, do not cache or act on any information from external components. Assume that any function, method, or property on an external method has not been properly set up. You may set up values that don’t depend on other components here.
  • OnEnable() → With OnDisable() You may subscribe and unsubscribe from events on references cached in Awake() here.
  • Start()/Update() → Assuming you’ve stuck with the rules above, you generally should be ok.

Another important factor in race conditions is the concept of caching values… As a very simple rule, don’t. The Fighter component shouldn’t cache the state of the current target, it should get the state of the target as it needs it, etc. Most bool states create more problems than they are designed to solve.

1 Like

I feel personally attacked by this :rofl: :rofl: :rofl: :rofl: :rofl:

Dirty little secret: I used to abuse George Boule’s invention to the extreme.

1 Like

Privacy & Terms