#I don't understand how to get a bootstrapper working

1 messages · Page 1 of 1 (latest)

left echo
#

I'm trying to implement a bootstrapper in my project that runs my game properly and allows me to play any scene in the editor without considerations. I'm also implementing a service locator. My current attempt is as follows :

namespace MindFactory
{
    public class Bootstrapper : MonoBehaviour
    {
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
        static void Init()
        {
            Application.runInBackground = true;
            RegisterService();

            string bootstrapSceneName = "Bootstrap";
            SceneIndex bootstrapSceneIndex = (SceneIndex)Enum.Parse(typeof(SceneIndex), bootstrapSceneName);
            SceneManager.LoadScene((int)bootstrapSceneIndex, LoadSceneMode.Single);
        }
        static void RegisterService()
        {
            Service.Register(new MindFactory.Scene());
        }
    }
}

I learnt yesterday that BeforeSceneLoad does not have any scene information available so I am just adding the bootstrap scene via LoadSceneMode.Single. I would prefer to do a check but I don't know how. Now I'm trying to register my scene manager and I'm getting the following error

You are trying to create a MonoBehaviour using the 'new' keyword.  This is not allowed.  MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all.

My understanding for why this occurred is anything running MonoBehavior needs to be attached to a game object. However, at BeforeSceneLoad I don't even have gameObjects loaded yet right? I'm going to be deal with audio, camera, event managers so I dont believe I can avoid MonoBehavior. I need references to audio mixers, AudioClips prefabs etc...

Any thoughts/help would be greatly appreciated. I'm totally stuck.

atomic bloom
#

I need references to audio mixers, AudioClips prefabs etc...
you don't need a monobehaviour to do that

left echo
#

Ok...I'm willing to go down the road of getting making sure none of my boostrapped / managers are monobehavior but I'm pretty sure I need it somewhere.

#

For example, My scene loader is loading scenes async and tracking progress for a loading bar.

#

It s all using couroutines/IEnumerator now

atomic bloom
#

a coroutine would need to be started on a monobehaviour, yeah

#

but that's about it, really

left echo
#

Unfortunately that means this approach won't then

#

And I can't work outside of BeforeSceneLoad as far as I know because I need all my services registered before the scene starts

left echo
#

Just to be clear...I would like to get this approach but if I can't is there any bootloader approach that allows use of Monos?

stuck stratus
#

Remember that async does not need a Monobehaviour