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.