Search Unity

UWP app capabilities don't seem to be working when built to an .appx package?

Discussion in 'Windows' started by jjennings1990, Nov 22, 2017.

  1. jjennings1990

    jjennings1990

    Joined:
    Oct 25, 2012
    Posts:
    132
    Hi everyone I am building a Universal Windows app that needs to reference an external folder of assets . In editor it works perfectly fine , I can read from the desktop , SD Cards, Pictures folder, the persistent data path , everywhere. However for some reason The moment I export the build to a .appx package I am getting read errors which break my build ( Unfortunately no errors that I can read on the debug console ). It works flawlessly in editor but the builds are just a no-go . The one solution I have tried that works is putting the assets into the Resources folder and loading them there which works but our assets are huge and there are a ton of them so It's an unpractical solution at the moment .

    Has anyone else had an issue like this where enabling the capabilities in the build didn't seem to actually unable the read/write ability of the project. This app was built for the Mixed Reality headset but honestly can't imagine a UWP app would work different in term of permissions or securities just because it's in VR right? Otherwise what is the point of a UNIVERSAL platform ?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    How are you loading the said assets, which capabilities are you using and where are you loading them from?
     
    jjennings1990 likes this.
  3. jjennings1990

    jjennings1990

    Joined:
    Oct 25, 2012
    Posts:
    132
    We are reading in the assets using File.ReadAllBytes () and creating a texture from the Bytes we retrieve at the given path ( Like I said this part works flawlessly in the editor) . The relevant capabilities I have enabled and tested are PictureLibrary and Removable Storage which I used to load from The local Pictures folder on my machine and an external SD Card drive respectively. Again those Paths are fine in editor and I am not hard coding them .

    The fact that I couldn't load the textures when placing the folder at the location of our Persistent Data Path truly confused me I assumed all unity projects would have access to that.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    Persistent data path should definitely have worked just fine. Can you share the code?

    UWP unfortunately does not support reading from these special locations using File.ReadAllBytes. I heard this is something they plan to add support for in the platform in the future.

    You can use WWW class, or call into Windows StorageFile APIs directly instead to read from places like PictureLibrary or Removable Storage.
     
  5. jjennings1990

    jjennings1990

    Joined:
    Oct 25, 2012
    Posts:
    132
    I can, so essentially the crux of the code looks like this

    Code (CSharp):
    1. string[] leftPath = PathConstructer.GetPaths(index * 10, 1, 1, wizard.SelectedEntry, true, 1024);
    2.             //Debug.Log("Left Eye Path: " + leftPath[0]);
    3.             //leftShutter.texture = Portal.LoadImageFromCache(downloader.DownloadedImageLibrary.leftPath[index]);
    4.             Texture2D leftTex = new Texture2D(2, 2);
    5.             leftTex.LoadImage(File.ReadAllBytes(leftPath[0]));
    6.          
    7.            leftShutter.texture = leftTex;
    , it's repeated in several places and we do it for both right eye and left eye images.

    the Pathconstructer Class is where we form a Path based on whether our build is local or from an External source and truly the only difference in the path there is the inclusion of Application.PersistentDatapath into the path we use for our strings.


    However if File.ReadAllBytes just doesn't work with UWP apps at all at the moment that would explain why it wouldn't function even reading from the Persistent Data path right ?


    However can you go into further detail about using the Windows StorageFile APIs directly? I'm new to windows Development so excuse my ignorance.
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    jjennings1990 likes this.
  7. jjennings1990

    jjennings1990

    Joined:
    Oct 25, 2012
    Posts:
    132
    I talked with my Lead Programmer and we will probably just be Loading from the WWW but in one message you've helped me understand something I've been bashing my head against for a week . Thank you.

    I deleted the original code but it was very simple Essentially all I added to our path Constructor was

    Code (CSharp):
    1. string pathSuffix = @"\HomeFolder\Assets\";
    2.                 string dataPath =     Application.persistentDataPath + pathSuffix;
    and this was the DataPath we would try to read our bytes from .

    I don't know if it will help much but the persistent data path returned for this was essentially ( slightly scrubbed)

    C:\Users\ jjennings1990 MS MR\AppData\LocalLow\UnityProject\UnityProject\

    and after that is where I appended the actual Folder names for our Asset Folder and it's child folders and also where I placed the assets themselves
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    That doesn't sound right. That's persistentDataPath for the editor/standalone player, but it would be different for UWP app. Are you sure you didn't hardcode that path somewhere?
     
  9. jjennings1990

    jjennings1990

    Joined:
    Oct 25, 2012
    Posts:
    132
    I'm very sure that the path wasn't hardcoded but if that Persistent data path would be different for the UWP app ( something I was unaware of) most likely my assets weren't in the correct location in the first place so I will look into outputting the logs within the UWP app build as well just to see if I can find what it's persistent data path would look like. I was having an issue where only certain unity logs were showing in Visual Studio so that's a whole different problem I need to check out .
     
  10. Relaycars

    Relaycars

    Joined:
    Mar 28, 2016
    Posts:
    12
    @Tautvydas-Zilys You were correct I was looking at Unitys Persistent data path not the data path of my build , I output the path the build was finding , placed the assets inside of it and now everything is working fine. Thank you so much for your help !