I feel like this should be easy to do I’m just not sure how to find this. I want to run a quick setup before gameobjects and components are created and added to a scene, like creating my UnitManager and other such necessary elements for my game to function. Where would I add this code? I would assume this is not something I want to do with components as all of this setup is required before most components should even be created.
I think I may have thought about my issue incorrectly in the context of how Unity3d works. I think I am supposed to create an empty gameobject and add any scripts that must run on the creation of the scene there. Please someone correct me if there is a better way of doing this.
That’s pretty much it. Many people have an empty “Startup/GameManager/Bootstrapper” GameObject in their scene. It’s on this object’s awake/start method that they programmatically instantiate or manage all the other objects in the scene.
Otherwise, you can place code in the script’s “Awake” method. All object’s Awakes will run before their Starts, so you could manage your logic that way as well.
I was confused. The previous game I created had a whole startup process I run before any enemies or players etc. were added, and this code was not related to any objects or levels. However it appears in unity that all scripts must be tied in to a gameobject in some way or another, even if that gameobject has no visual representation.
That’s correct. (Excluding editor scripts at least.)