Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Environment.SpecialFolder.MyDocuments BUG?

Discussion in 'Windows' started by RandomCharacters, Mar 25, 2020.

  1. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    .
     
    Last edited: May 21, 2020
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    First of all, there's no such thing as running UWP in the editor. Editor is a win32 application and will behave the same as Windows Standalone player.

    When you say the text file isn't saved, did you check which directory it's trying to write to? Do you get any managed exceptions?

    Did you enable any of the file system capabilities? UWP apps don't have access to documents folder by default.
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Yes, that option is only there if you declare "broadFileSystemAccess". However, using that specific capability makes it harder to get accepted to the Windows Store as it's considered "restricted capability".

    To be honest, what it sounds you should do instead is give user a folder picker and let them select the location they want you to save the files to. You can default it to somewhere like documents. Once folder picker is accepted, you're allowed to access those files without any capabilities or restrictions.
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    It's in generated Visual Studio project.

    Something like this:

    Code (csharp):
    1. #if ENABLE_WINMD_SUPPORT && UNITY_WSA
    2. static async Task<string> PickFolderAsync()
    3. {
    4.     var folderPicker = new Windows.Storage.Pickers.FolderPicker();
    5.     folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
    6.     folderPicker.FileTypeFilter.Add("*");
    7.  
    8.     var folder = await folderPicker.PickSingleFolderAsync();
    9.     if (folder != null)
    10.     {
    11.         Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(folder);
    12.         return folder.Path;
    13.     }
    14.  
    15.     return null; // dialog was cancelled
    16. }
    17. #endif
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    It's up to you. You can either ask the location first time you run, or every time your start your app - that's up to you. In both cases you'll have access to the folder path the person using your app picks. You can then write whatever files you want there.

    You don't need any permissions to use folder picker.
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Yeah you could save the path to player prefs.

    There used to be more options in the past. I believe they were removed very recently.
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Does the build fail when you build from Unity? Sometimes intellisense can get messed up on those player projects.
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Unity uses C# 7 right now I believe.
     
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Nothing should stop working. Unity doesn't care how you configure the VS project.
     
  12. ceitel

    ceitel

    Joined:
    Jan 3, 2017
    Posts:
    35

    @Tautvydas-Zilys Just wondering if this code block/method will work for a UWP VR app and whether the user will be prompted in VR or on the monitor?

    Thanks
     
  13. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    I have no idea. You'll have you try it yourself. Would love to hear the results!