Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

[Solved] How to copy file from StreamingAssets folder in Windows Store app? (8.1)

Discussion in 'Windows' started by KungFooMasta, Mar 6, 2015.

  1. KungFooMasta

    KungFooMasta

    Joined:
    May 27, 2014
    Posts:
    24
    In my game I have several files to represent the starting point of the game, used on first play, and also in case user wants to start over.

    I'm trying to copy files from the StreamingAssets folder to the Application's LocalFolder, but unable to locate the StreamingAssets folder. How should this be done?

    My Code:

    StorageFolder streamingAssetsFolder = null;
    Task.Run(
    async () =>
    {
    streamingAssetsFolder = await StorageFolder.GetFolderFromPathAsync(Application.streamingAssetsPath);
    }).Wait();

    streamingAssetsFolder is null after the call, causing the problem. (The code above is a way to call async code synchronously, without using the "async" keyword in my function signature)
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,755
    The code looks fine. What if you do everything inside task?
     
  3. KungFooMasta

    KungFooMasta

    Joined:
    May 27, 2014
    Posts:
    24
    I moved everything inside the task, and still the same exception. But I checked the app's Local Folder, and I don't see my content! I'm expecting to see the "StreamingAssets" folder with all my files inside. Are there any known issues with the "StreamingAssets" folder and copying it upon app installation in Windows 8.1?

    Unity version: 4.6.1f1
    Build Settings: Windows Store. SDK 8.1. Type Xaml C# Solution. Compilation Overrides: Use Net Core

    1>------ Deploy started: Project: Tomb Town, Configuration: Master x86 ------
    1>Updating the layout...
    1>Deployment complete (353ms). Full package name: "2456StormsongEntertainmen.TombTown_1.1.0.0_x86__sgrqz1vmqnepp"
    ========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
    ========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

    When I look at this location, I do not see any of my files:

    C:\Users\bkinsey\AppData\Local\Packages\2456StormsongEntertainmen.TombTown_sgrqz1vmqnepp\LocalState

    Should I create a new thread for this? Either I'm doing something wrong or StreamingAssets is not working for Windows Store Apps. (worked for windows phone 8.0 and PC platforms)
     
  4. KungFooMasta

    KungFooMasta

    Joined:
    May 27, 2014
    Posts:
    24
    I got this to work. Posting solution in case it helps anybody:

    Code (CSharp):
    1.  
    2. #elif NETFX_CORE
    3.         Task.Run(
    4.             async () =>
    5.             {
    6.                 StorageFolder dataFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Data");
    7.                 StorageFolder streamingAssetsFolder = await dataFolder.GetFolderAsync("StreamingAssets");
    8.  
    9.                 foreach(string fileName in mGameFiles)
    10.                 {
    11.                     StorageFile file = await streamingAssetsFolder.GetFileAsync(fileName);
    12.  
    13.                     await file.CopyAsync(ApplicationData.Current.LocalFolder, fileName, NameCollisionOption.ReplaceExisting);
    14.                 }
    15.             }).Wait();
    16. #else
    17.  
     
    GlibEngie likes this.
  5. CanadianGuy43

    CanadianGuy43

    Joined:
    Feb 3, 2013
    Posts:
    2
    Thanks for the solution KungFooMasta - it helped!!