Search Unity

Working with assets placed in the StreamingAssets folder

Discussion in 'Editor & General Support' started by fredrik-larsson, Nov 1, 2016.

  1. fredrik-larsson

    fredrik-larsson

    Joined:
    Nov 3, 2015
    Posts:
    29
    I've encountered an issue when using the /StreamingAssets/ folder.

    If a GameObject or Prefab in a scene or in the project view has an asset referenced to it in the inspector and this asset is moved to the /StreamingAssets/ folder the reference is still valid.

    However if a reimport of the moved asset or project is triggered, ALL references to this asset becomes a "Missing asset".

    If the asset is then moved to a folder other than /StreamingAssets/ and you trigger a reimport, the references will become valid once again.

    If AudioClips are placed in the /StreamingAssets/ folder, you are unable to change any import settings for the clips and these will become invalidated once you hit "Apply".

    Does anyone know how to use the /StreamingAssets/ folder when working with referenced assets?
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Hi

    You should not reference assets in StreamingAssets folder directly.

    Asset in the StreamingAssets folder does not go through the entire import process and are only handle by what we call the DefaultImporter, an importer that does nothing.

    The reason for this is that StreamingAssets folder are meant for larger streaming files like Video, Audio or Assetbundles. When you put files in the StreamingAssets folder you are telling Unity that you want to load these files yourself during game play and you don't want to waste hours importing large video files.

    Files put into the StreamingAssets folder is copied without any processing to your final build.

    https://docs.unity3d.com/Manual/StreamingAssets.html

    So what you are currently seeing is actually the intended behaviour though there is a bug with moving files in and out of the StreamingAssets folder because a reimport should be triggered automatically. This bug has been fixed in 5.6.

    So in conclusion StreamingAssets folder can't be used for referenced assets.
     
    Teagarden and Deleted User like this.
  3. fredrik-larsson

    fredrik-larsson

    Joined:
    Nov 3, 2015
    Posts:
    29
    Thanks for the response. This should probably be explicitly stated in the documentation at https://docs.unity3d.com/Manual/StreamingAssets.html.

    The reason we are doing this is because we want to work with referenced assets while also have the possibility of streaming them on the consoles. We make use of the StreamingAssets folder to make sure streamed assets are included into the packaged builds.

    We are also unable to split our AudioClip assets into AssetBundles due to the bug of not being able to play streaming clips from assetbundles: https://forum.unity3d.com/threads/f...error-with-asset-bundles.431456/#post-2826584

    We've also been recommended not to use the Resources folder due to the increase in startup times and patch sizes that is the side effect of increasing the Resources folder size.

    How would one go about circumventing this issue?
     
  4. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    The fix for the issue with the audio clip is hopefully soon released, see the other thread for more info.

    We don't support and currently have no plans to support referencing assets in StreamingAssets folder.

    If the only reason you are trying to do this is because of the audio clip bug, I would say you should not try to work around but continue to use asset bundles, once the fix ships your problem is solved.
     
  5. fredrik-larsson

    fredrik-larsson

    Joined:
    Nov 3, 2015
    Posts:
    29
    Thank you!
     
  6. fredrik-larsson

    fredrik-larsson

    Joined:
    Nov 3, 2015
    Posts:
    29
    So unfortunately this fix appears to only be for the iOS platform and I'm experiencing this issue on the PC, XboxOne and PS4. Here is my response to the other thread:





    Yes I'm seeing this issue on the XboxOne, PS4 and PC platforms currently.

    Here is a link to a forum post I wrote on the issue: https://forum.unity3d.com/threads/l...assetbundles-in-unity-5-does-not-work.434881/

    We are also experiencing this: https://forum.unity3d.com/threads/streaming-audio-error-cannot-create-fmod-sound-instance.431824/ when streaming audio from the WWW class and /StreamingAssets/ folder.

    If I build an AssetBundle with a referenced AudioClip being placed in the /StreamingAssets/ folder will this cause the error this thread talks about? The relevant AssetBundle is not unloaded or unreferenced while we are waiting for streaming to complete.
     
  7. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    But if you put the audio file in StreamingAssets folder it will not be imported as an AudioClip but as a DefaultAsset and the AssetBundle system will simply treat it as a DefaultAsset, so that will not work.

    You should place your audio files outside the StreamingAssets folder if you want them included in an AssetBundle.
     
  8. fredrik-larsson

    fredrik-larsson

    Joined:
    Nov 3, 2015
    Posts:
    29
  9. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Right, but that is a different issue which I hope there has been reported a bug for and Audio team is looking into.
     
  10. thieum

    thieum

    Joined:
    Apr 8, 2011
    Posts:
    61
    Bumping into this as I was struggling with an updated .mp4 file no longer available when placed in StreamingAssets folder.
    My case is a WebGL build mainly dealing with videos, and only one clip in a series of 6 had this issue, right after renaming the file (but why did I do this... :()

    Thanks to this thread, I learned about the specific importer for StreamingAssets folder, and above mentioned limitations... scratched my head as my other clips were correctly referenced.

    It turns out that I simply made some kind of newbie misuse : my transcoded mp4 files were originally in a "videos" folder, that I renamed "StreamingAssets" later on, and the magic happens : the references in scripts are correctly updated, the mp4 files built aside in the StreamingAssets folder on the server, and everything runs as expected. I just wonder if transcoding is there finally, as the mp4 files show the same size as the imported files.

    I could reproduce it as to bring back the renamed video in the StreamingAssets - i.e. without any manual file dropping in the editor, only renaming the folder - and the file shows up correctly in the inspector now.

    o_O Did I override Unity Editor behavior by chance ?
     
  11. Prependicular

    Prependicular

    Joined:
    Apr 17, 2013
    Posts:
    4
    @SteenLund Not sure but its still quite confusing for understanding which one is better to use streamingAssets or Resources?
    and does it effects the build size if we move our assets into streamingAssets folder instead of Resources Folder ?
     
  12. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    Either way the data is going to end up in your build, so using one over the other for size reasons doesn't really make sense.

    Resources and StreamingAssets aren't really directly comparable. One is for loading assets that have been imported, whereas the other is for managing non-imported files.