Search Unity

Programmatically create Unity assets at runtime

Discussion in 'Scripting' started by JeremiahJ, Jul 18, 2018.

  1. JeremiahJ

    JeremiahJ

    Joined:
    Nov 1, 2016
    Posts:
    28
    (this is a non-game problem.)

    I have millions of files that I need to convert into Unity assets and then into asset bundles so that I can load them at runtime. This number grows by several thousand each day, and I need to keep up with those new files in something close to real time.

    I can't create an asset bundle out of something that isn't already an asset, so I need to import/convert these things into Unity assets programmatically, on demand, any time, day or night.

    Several thousand each day, remember. Backlog of millions.

    Is there any way to script this without installing the full editor on the server and running headless?
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,332
    The asset conversion process is editor-only. I think your only solutions are:
    - full editor on server in headless mode
    - dropping asset bundles and parsing the files manually.
    - getting source code license.

    You should probably post in the relevant forums, either for Asset Bundles or for Addressables. It might be that there's something relevant on the horizon.
     
  3. JeremiahJ

    JeremiahJ

    Joined:
    Nov 1, 2016
    Posts:
    28
    Thanks. Source code license is probably not feasible. I can parse the files manually (this is how I import them into Unity now) but it's very slow, for some reason.

    I guess alternately I can convert these 3D files to glTF then load them at runtime with UnityGLTF, but none of these models have textures, and thusly no UVs, so no normal map, no textures, etc. It might be best for me to update my conversion tool to convert vertex normals to a normal map, and vertex colors to a texture, somehow...
     
  4. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
  5. JeremiahJ

    JeremiahJ

    Joined:
    Nov 1, 2016
    Posts:
    28
    FBX is definitely not the format you choose when you want to load something quickly. glTF is superior to FBX in this regard, and the UnityGLTF plugin can easily load glTF at runtime. Unity isn't the only engine I'm using, though, and other engines aren't as friendly to glTF as Unity is with the UnityGLTF plugin. For a while I was considering storing native engine assets for each engine we're planning on using, but that just isn't going to scale well.
     
    astracat111 likes this.
  6. Deleted User

    Deleted User

    Guest

    Hey, I am having trouble using unityGLTF at runtime. Is there any tutorial ??
     
  7. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,406
  8. JeremiahJ

    JeremiahJ

    Joined:
    Nov 1, 2016
    Posts:
    28
    yeah, this doesn't support importing glTF, though.
     
  9. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Just out of curiosity, why multiple engines?
     
  10. JeremiahJ

    JeremiahJ

    Joined:
    Nov 1, 2016
    Posts:
    28
    Because I don't use only Unity, and there are scenarios where (insert another 3D engine here) would be a better choice for a given use case. I don't want to have to create an engine-specific asset for every engine that could potentially be used. If possible, I want to convert models to a single engine-agnostic format for all engines to use at runtime.

    It might be that I have to create my own format for this.
     
    astracat111 and Aiursrage2k like this.