Search Unity

Windows.Storage not available?

Discussion in 'Windows' started by zumwalt, Jun 20, 2021.

  1. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I am trying to build a UWP game and be able to read/write into the local store, but when i try to include the Windows.Storage it is not a known library, I am using 2019.4.28f1, is it not in this version of Unity? I want to keep a persistent save of player data and when I do updates and push, the playerprefs is reset so i can't use that method, so since UWP doesn't use File.IO I need to use Windows.Storage, any suggestions?
     
    krish_holo likes this.
  2. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    WinRT APIs are platform specific and only available when building for UWP platform, i.e. they're not available in the Editor. Calls to these APIs must be enclosed by #ifdefs in your scripts.

    Please see Unity documentation for details: https://docs.unity3d.com/Manual/windowsstore-scripts.html
     
    krish_holo likes this.
  3. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    My whole issue is the use of this for XBOX Live publishing, apparently the package on
    microsoft/xbox-live-unity-plugin
    isn't made for 2019? is there a current version to use to publish to xbox live and use the internal API? The documentation on the xbox live stuff, doesn't actually help for using Unity anymore, not after version 2017 from what I can tell, I have pushed games to the device but have zero access to my sandbox, local/cloud store, leaderboards, etc, and I have been through the information at:
    Xbox Live documentation - Xbox Live | Microsoft Docs
    Thanks for the documentation link, they want me to publish my game on the xbox live first before getting the XBOX@ID part, running into a lot of brick walls right now, trying to wind my way through them for each piece.
     
  4. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    So, to be clear: you're trying to use the Xbox SDX (i.e. for "real" Xbox games) and not UWP on Xbox.

    Unfortunately, I can't help much in that case; I don't have access to the Xbox SDK nor ID@XBOX resources. Also, since ID@XBOX is NDA we can't post about it on public forums. I'm also afraid don't know much about the Xbox Live plugin.

    Are you able to access the "Microsoft Game Core on Xbox" or "Xbox One Development" forums? This problem would be better answered there, but I think these forums are under NDA and require special permission to access them.
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    There seems to be a bit of confusion in this thread. Let's get this clear: are you trying to publish a UWP or an ID@XBOX game?

    Secondly, this statement is incorrect:
    UWP can use File.IO stuff just fine ever since we introduced IL2CPP.

    Lastly, to use Windows.Storage namespace, just wrap it in conditional compilation:

    Code (csharp):
    1. #if UNITY_WSA && ENABLE_WINMD_SUPPORT
    2. Windows.Storage.File = ....
    3. #endif
     
  6. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Those forums are not available to just XBOX Live / Store, only the XBOX@ID unfortunately.
    And they want to have my app on the store for XBOX Live first, and when I build with Unity to UWP, it only will build up as Windows or Phone not Universal, been fighting that fight with the configuration for a week now.
    I get so close, only for it to tell me as I publish to the S, that the package is not made for that device, still trying to figure out why. It works just fine for Windows UWP build though and installs as an App just fine on Windows 10 using that build target, just not XBOX, if I ever figure this out, I will try to do some documentation on it. Thanks for the info though.
     
  7. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    In Unity if you change the target to Universal Windows, Unity itself will not allow you to build with using File.IO, the namespace is not known. But I am using 2019.4.28f1

    So, no I am not posting to the XBOX@ID, can't do that yet, I have my Sony partnership done, but Microsoft wants the game on there xbox live marketplace first, a build UWP version only seems to build and run on Windows 10 for my game, haven't figured out exactly why.
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    That doesn't sound right. Can you attach a script that doesn't compile?

    Also, the fact that the app doesn't work when deployed to Xbox is a completely different issue and has nothing to do with Xbox Live SDK. What exactly happens when you try to run your UWP app on Xbox?
     
  9. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I found out why the app won't deploy to my XBOX S, its because it is 2.5 GB in size, and the thread i found on the size dev change doesn't exist in the latest version of the dev app:
    Xbox Live Creators Program Game File Size Limit? - Unity Forum

    From reading this article, I am actually limited to 2GB with Universal Windows Builds:
    Xbox Series S and X Developer Mode: 3 things you can do with it, and 3 you can't - TechRepublic

    I guess texture compression time is needed to reduce the project size now.

    That is something that existed in XBOX One older version, the app checks out ok using the tool for the app checker, all pass (only after I removed substance, apparently that is not an allowed library set for Microsoft), so I am trying to find where to change the dev space, I have 300 gb available but get the out of space problem, which is new today, before it wouldn't give me any reason. I have put back in the code that I had that wasn't working which is simply, this (parts)
    // it doesn't know what System.IO is, that is the problem i am having
    // cleaning out the Library folder again for a full rebuild again
    using System.IO;

    virtual public bool LoadGame(string filename)
    {
    if (File.Exists(filename))
    {
    string FileResource = File.ReadAllText(filename);
    if (null != FileResource)
    {
    bool i = Parse(Decode(FileResource));
    string p = ToString(true);
    Debug.Log($"LoadGame {i}: {p}");
    return i;
    }

    return false;
    }
    else
    {
    return false;
    }
    }
     
    Last edited: Jun 24, 2021
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    The code you pasted isn't complete, but putting it into a script works just fine for me (and I am able to build to UWP). Here's the full script that compiles:

    Code (csharp):
    1. using System;
    2. using System.IO;
    3. using UnityEngine;
    4.  
    5. public class NewBehaviourScript : MonoBehaviour
    6. {
    7.     virtual public bool LoadGame(string filename)
    8.     {
    9.         if (File.Exists(filename))
    10.         {
    11.             string FileResource = File.ReadAllText(filename);
    12.             if (null != FileResource)
    13.             {
    14.                 bool i = Parse(Decode(FileResource));
    15.                 string p = ToString(true);
    16.                 Debug.Log($"LoadGame {i}: {p}");
    17.                 return i;
    18.             }
    19.  
    20.             return false;
    21.         }
    22.         else
    23.         {
    24.             return false;
    25.         }
    26.     }
    27.  
    28.     private bool Parse(object arg)
    29.     {
    30.         throw new NotImplementedException();
    31.     }
    32.  
    33.     private string ToString(bool arg)
    34.     {
    35.         return arg.ToString();
    36.     }
    37.  
    38.     private object Decode(string fileResource)
    39.     {
    40.         throw new NotImplementedException();
    41.     }
    42. }
    Can you show your editor log after your get build errors?
     
  11. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    After deleting my Library folder and waiting on Unity to recompile everything, I was able to get it to build and make a package that pushed to my XBox S, also had to find all images and change them from there current size to 512 (1024 was still too large), game quality has clearly degraded but I was able to at least get it down to 1.6 GB in space which allows it to be pushed to the machine, now when I run it, using player prefs to try to save to, it simply crashes on the machine, trying to track that problem down now, but prior, the "using System.IO" was the problem, it was an unknown library, I do not have the exact error anymore, but I guess there was a linker issue of some sort, I use Visual Studio Pro 2019 with Unity 2019.4.28f1, I have learned that there are many different scenarios with this version where I have to just delete the Library folder and wait for a rebuild. I was able to associate the game with the app store just fine, and the package tester works and passes after I got rid of algorithmic's substance libraries and plugins. The new deployment pipeline in VS 2019 doesn't work with the Unity projects for some reason also gives a strange warnings about DLL's with zero specifics. The same UWP version of the game installs just fine on Windows 10 and runs without crashing when it uses playerprefs. I am not sure if this just means that the playerprefs is not compatible with a UWP build deployed on XBOX S/X, Thank you again for your help in trying to troubleshoot the System.IO issue.