Search Unity

More information on the PrefabBuilder node?

Discussion in 'Asset Bundles' started by strich, Oct 25, 2016.

  1. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    One major issue we have with AssetBundles at the moment is having an 'index' of prefabs. IE if we want to spawn characterXY we should be able to write code in the form of:

    Code (CSharp):
    1. // Best:
    2. var prefab = AssetManager.Characters.characterXY;
    3. // Okay:
    4. var prefab = AssetManager.Characters["characterXY"];
    5. // Crap:
    6. var prefab = myBundle.LoadAsset("Assets/bundles/characters/prefabs/characterXY");
    7.  
    8. var go = Instantiate(prefab);
    Can we use the PrefabBuilder node to generate that AssetManager class? Is this the intended use case for this? Thoughts?
     
  2. hiroki-unity

    hiroki-unity

    Joined:
    Jun 20, 2013
    Posts:
    21
    PrefabBuilder is intended to automate creating certain form of prefab from given assets. For example when you mass-produce enemy characters and know your enemy character have certain models, textures and audio and there are several components you know you need to add, this node helps you to automate that.

    Graph tool might solve your problem - you could use Postprocess for that.
    What is your expected behavior when accessing AssetManager.Characters.characterXY? Does it call loading Assetbundle internally and block until load complete? (but still AssetManager resolves where the assetbundle is by itself)

    Once I know your expectation I might be able to come up with some example to solve this.

     
  3. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    We wrote our own inspired `AssetBundleManager` that will load the AB as required (If not already), yeah. `AssetManager` should really just be an index of prefab pointers so as to avoid hardcoded path/filename strings that may break at any time.
     
  4. hiroki-unity

    hiroki-unity

    Joined:
    Jun 20, 2013
    Posts:
    21
    Understood. There is a known issue that Postprocess is not getting result of Exporter node which would be mandatory for this use case, but once I fix that I think I can come up with some example script to generate AssetBundleManager class script to keep the index of asstbundles and prefab, allowing the your way of use.

    Internally it will still use some hardcoded strings to address AB, but since it is auto-generated it should keep the relationship always in sync.
     
    strich likes this.
  5. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    Fantastic. Sounds like a good plan - And yeah hardcoded path strings for the ABs is fine. Could possibly outsource that to some config file at a later point.