Search Unity

Accessing external Assets during runtime.

Discussion in 'Asset Bundles' started by Uteki, Apr 22, 2021.

  1. Uteki

    Uteki

    Joined:
    Apr 17, 2017
    Posts:
    13
    Hello,
    I have quite strict requirements a cannot seem to find a way to fulfill them. I need to open and initialize assets during runtime from one or multiple files that are not referenced in any way during Project Development.

    The best would be ability to use FileStream or File itself bu it seems to be not supported for some esoteric reasons.

    Addressable Assets are out of question because you literary need to keep addresses of third party data in form of tags and other references. Data you don't have access to.


    AssetBundles don't want to work at all.
    https://docs.unity3d.com/2021.1/Documentation/Manual/AssetBundles-Workflow.html Is one of the most unhelpful documentations I have read, for example:
    • At the bottom of the Inspector, there is a section to assign AssetBundles and Variants. Use the left-hand drop down to assign the AssetBundle, and the right-hand drop down to assign the variant.
    Well I haven't found such section anywhere, and a screenshot is apparently to much to ask for.

    So my question is:
    Can you open and instantiate directly assets from files during runtime? If not, is there any documentation or blog or any form of information why was such design decision taken?

    Are you able to open AssetBundles or AddressableAssets created in different unity projects during runtime of another project? If you can, how to achieve it?
     
  2. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    353
    Can you define what you mean by 'assets'? If they are (for example) videos then you can just use unitywebrequest to store them locally, and then assign them to a videoplayer by path. Same goes for audio, or whatever custom binary type your application supports.

    Things get more complicated if these assets need to be imported and built by the unity editor for the runtime to be able to handle them, for example materials or complex 3D. In that case, assetbundles or addressables are definately the way to go.

    https://docs.unity3d.com/ScriptReference/AssetBundle.GetAllAssetNames.html

    That function for example can iterate over all assets in a bundle, which you can then instantiate like so:

    https://docs.unity3d.com/ScriptReference/AssetBundle.LoadAssetAsync.html
     
  3. Uteki

    Uteki

    Joined:
    Apr 17, 2017
    Posts:
    13
    I was talking mostly about *.prefab files.

    Thanks for the reply but I already managed to get AssetBundles to work, addressables were discarded because they need preconfiguration.

    If somebody also has problem with configuring them. I advise you to look for an answer in third party tutorial from YouTube or other site rather than looking through official documentation.

    Cheers
     
unityunity