Subclassing the Application class

This is more of a feature request and general question rather than a specific scripting question…

The basic issue is that a game almost always consists of more than one scene with common data or a common controlling class. So my natural assumption is that there should be a way to subclass the Application class and place common functionality such as a data manager, game start / stop logic, file reading / writing, etc. in that class rather than in any one scene. I realize you can put this kind of thing in your first scene and make a static class or function and use “DontDestroyOnLoad” to maintain across scenes. But it seems like a kludge. Your manager code is still dependent on being initialized from a scene.

Does anyone have a good answer why Unity took this approach and why there isn’t a “scene superclass” that allows such management outside of scene code, and without using DontDestroyOnLoad? Maybe the answer is “efficiency” and “speed of execution”, but to me it seems like an oversight and shortcoming of the architecture.

Just my $.02.

– Brian

Any comments on this? It’s curious to me why Unity provides no “Application” or “Game” object that can be subclassed and runs independent of any scene. There is an “Application” class but it’s read only.

This is not an oversight but by design. The Application class is meant to be the application’s interface to the runtime environment, so subclassing it does not really make sense.

Having a central Game class is not really necessary, as Unity is designed around implementing functionality as discrete components or behaviors. This enables greater reuse of code between projects.

In fact, for a global game class you could use any static class, although most games use one or more manager classes attached to a game object in the first scene. Manager classes are usually singleton classes and have a static attribute or property to enable easy access to its instance. See the Unify wiki page about manager classes for an example.