Search Unity

Create an AssetBundle from assets generated during runtime

Discussion in 'Scripting' started by kenmarold, Jun 16, 2017.

  1. kenmarold

    kenmarold

    Joined:
    Jun 11, 2015
    Posts:
    27
    A quick question, is there a method to create an asset bundle from an application that is already running? I have an application that generates a texture2d png and an xml file and I would like to then take those files while the application is running, storing them in a temp folder, create an asset bundle of those files and then upload them to a server. Is this possible and are there any examples/tutorials on how to this? All of the examples I've come across are how to create asset bundles from within the unity editor. thanks!
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Nope... there's no way to create AssetBundles without the UnityEditor namespace, and that isn't available out side of the editor.

    You could write your own container format where you write out the information about your GameObject structure, including what components and everything should be added to them.

    Then when you load in the container format, you just parse it, and build a GameObject in the same manner.

    //edit
    Oh you say it's a png and xml file. Yeah, don't even really need what I just said. Just zip that stuff up and upload away. Is there a reason you need this as an AssetBundle?
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You can run the editor from your external application, and script it to import the files, then have it export the assetbundles, then close.

    But as @lordofduct pointed out, you can load png and xml files directly at runtime, no need to go through the bundle process.
     
    nifilo_unity likes this.
  4. kenmarold

    kenmarold

    Joined:
    Jun 11, 2015
    Posts:
    27
    Thank you for pointing me in the right direction! What would be the basic steps in creating a container format to hold my assets?
     
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Well png files and xml files can just be zipped up. So just create a zip file. Or you can even just store them raw.

    tar balls are another good option (tar balls can be compressed, but can just be flat as well... it's where they get the 'tar' part of their name. They stick files together).

    ...

    You only need to design your own container if you wanted to store GameObject/Component hierarchies, and other serializable data from your project.
     
    kenmarold likes this.