Search Unity

Delaying Default World Initialization Until Loading Scene is Finished

Discussion in 'Entity Component System' started by zanius, Dec 6, 2019.

  1. zanius

    zanius

    Joined:
    Feb 5, 2018
    Posts:
    24
    I'm having an issue where I need to access assets in the OnCreate method of several of my systems. I have a loading scene and a game scene, I would like to delay my custom bootstrap until the actual game scene has been loaded and the loading scene is finished loading up all the assets I need.

    Previously I was using "#define UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP" and then not initializing the world with "DefaultWorldInitialization.Initialize("Default World", false);" until the loading scene was finished. That doesn't seem to work anymore. Is there anyway to delay my systems from running?

    I have a custom bootstrap working, but it just runs as soon as the game starts.
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    Using the OnCreate method of a system to load assets dependent on the active scene smells like an OOP design. Traditionally with ECS, you load up all your systems and logic before any content gets displayed, and then you run systems (OnUpdate) to do your loading and initialization when some entity data exists requesting you to do so. The purpose of OnCreate is for the system to initialize data structures and queries it needs independent of the context of the world.
     
    vildauget, elcionap and Vacummus like this.