Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How do you use SceneSystem.LoadPrefabAsync()?

Discussion in 'Entity Component System' started by davenirline, May 17, 2023.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    944
    I wanted to load a bunch of entity prefabs which I then keep in a hash map. The way it is done now is to put them via a baker then using GetEntity() on these prefabs. The containing GameObject is then placed in a subscene. But this is awkward because it happens way later when the systems are already created. I need to add code to stop systems from running before these prefabs are loaded. It's cumbersome to add these in every system. I wanted these hash map of prefabs to be loaded first so other systems can reference them already.

    I've run across the method SceneSystem.LoadPrefabAsync() on the "Meet the team" thread. I thought that this was a life saver but when I tried it, the bakers of the components of the prefabs are not invoked. I assumed that was what it does but I was wrong or maybe I'm just using it wrong. Any of you had any experience of using this? Or what should be my approach for my use case?
     
  2. yondercode

    yondercode

    Joined:
    Jun 11, 2018
    Posts:
    27
    I don't think
    SceneSystem.LoadPrefabAsync()
    would work as you expect. It returns the loading state, it takes a few frames until the prefab is actually loaded in my tests.
    Do you mean the baking process execution? I see this is the case when your subscene is in the live conversion mode. When you close the subscene in the hierarchy window, the baker will be executed ahead of time and the prefab entities will be serialized in the subscene.

    Where are these hash maps located?
     
  3. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    944
    How did you identify that the prefab is already loaded? I tried waiting until the PrefabRoot component is added but when I checked if the other components from authoring are really added, they're not there.