Script Execution Order doesn't affect derived classes.

So I need script Start() methods to be called in a certain order. I was hoping Unity would support custom LateStart (and EarlyStart) methods or something where I can specify (in code) a priority or order number to indicate when that method is called. Unfortunately, the closest thing I could get was using the Script Execution Order menu in the editor to order when scripts’ Awake()s and Start()s are called. This would be acceptable for me if setting a base class order would maintain that order for all of it’s derived classes. It doesn’t seem to do that. Because of that, I’d have to manually add each new derived class script I make to the order menu through the editor. If I could do this in code instead, it wouldn’t be an issue, but I have no idea how to do that. This is quite horrible for work flow when the game has a lot of content in the form of derived classes.

Before I make a static class with a list of delegates to call in their specified orders on the next update, I was wondering if there was a more elegant solution.

I’m quite surprised if I have to do this manually, honestly. I don’t know how people would make games where initialization orders of objects don’t matter. Hopefully I’m just missing something or perhaps I’m doing something wrong entirely. Do other developers never have initialization logic that relies on other scripts’ initializations? I can’t even imagine how I’d code without that… By default there’s just Awake() and Start(); that only allows for 2 layers of dependencies… In other words, if B.Start() requires A.Awake(), no problem. But if there’s a C.Start() that requires B.Start(), what do you do? Especially when C has dozens, perhaps hundreds, of derived classes.

I wind up using a lot of “manager” singletons when statics are overly cumbersome. I usually build a chain of events starting with a GameStateManager which handles the application state, user accounts, global options, etc. This calls Init(); on a single tier of manager scripts like pool managers, audio players, visual effect services…

After that I rarely have any logic requiring sequential dependencies. It becomes quite nice once you’re used to the routine.

I assume you’re having this problem because you’re setting things up in the scene and they all try to activate in an uncontrolled order. Best bet might be moving their activation logic into a method you call from a manager. Manager activates them in the sequence you choose based on some criteria like type or some kind of tagging system you create. Bummer, yes. Maybe SEO really IS the way to go in your case.