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 Can we force a certain Baker to run? Or is there another way?

Discussion in 'Entity Component System' started by davenirline, Jun 21, 2023.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    We have a scriptable object which just contains a list of AssetReferenceGameObject. This SO is then referenced by a MonoBehaviour that has a Baker and thus it's under a subscene. What this Baker does is convert the GameObject prefabs into entity prefabs using Baker.GetEntity(). We then store the entity prefabs in a NativeHashMap somewhere. We did this so we can instantiate entity prefabs by using some id.

    Here's the problem. The designers/artists are the ones who will add the prefabs on the scriptable object. The amount of prefabs will grow. However, the Baker may not run because the scene with subscene where the SO is referenced is not opened like say the designer is working on another scene. Thus, the newly added prefabs are not converted to entity prefabs. On play of the game, they get missing prefab errors.

    Is there a way to force the prefab loader Baker to run again to account for the new prefabs? Like say when the SO is updated or even at runtime?
     
    bb8_1 likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Scenes don't need to be open to bake, just sounds like you're missing correct DependsOn in your baker to track changes.
     
    bb8_1 and davenirline like this.
  3. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    Ok, that's new. How do I use that? Is there a documentation?
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    bb8_1 and davenirline like this.
  5. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    I mean it's new to me.
     
    bb8_1 and PolarTron like this.
  6. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    So I tried DependsOn() but it doesn't seem to work for ScriptableObjects. It only works when the scene with the subscene that references the SO is opened.
     
  7. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    I can say that it definitely works as my entire settings setup depends on it and I never have open subscenes.

    The one gotcha is that you need to save your scriptableobject before changes will be detected.
     
  8. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    Ah, I see.
     
  9. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    Still doesn't work. How do you save your scriptable objects? Is this the same as File > Save?
     
  10. mattdymott

    mattdymott

    Joined:
    Dec 27, 2016
    Posts:
    29
  11. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    Yeah just ctrl-s/file - save. Just tested this and it does rebake the updated scriptableobject's data inside a closed subscene.
     
  12. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    Is the scene with subscene opened? It has to work while this scene is not opened (like another set of scenes are being worked on).