Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality. If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers. And always feel free to hit us up on Twitter @MxdRealityDev.

Still having a problem with asynchronous calls using Unity5.40f3-HTP with HoloLens

I have previously found that Microsoft's recommended version of Unity which is HoloLens compatible to be version 5.40f3-HTP. I believe currently this is the latest one available. I have spend this morning carefully going through a procedure using as my starting point the much used recipe of following the tutorial of Holograms 101E

https://developer.microsoft.com/en-us/windows/holographic/holograms_101e

We get the usual sort of picture on the emulator:-

Now the next steps are where trouble starts brewing. Firstly define a new C# script in Assets. This time add in a 'using' clause:-

using Windows.Storage;

In the class it self add in 3 static lines:-

        static StorageFolder storageFolder = null;
        static public StorageFile writefile = null;
        static public StorageFile readfile = null;

In the 'Start()' routine add in:-

        void Start()
        {
            set_data_folder();
        }

Then add a static procedure to the class:-

    static async void set_data_folder()
    {
        var storageFolder = await KnownFolders.GetFolderForUserAsync(null /* current user */, KnownFolderId.DocumentsLibrary);
    }

Then save it. Please note this part of the code is not called by any other part of the coding structure. It is only there as a Monobehavioral Class.

Now go back to Unity and proceed by clicking 'Build Settings' then 'Build. The process proceeds to Visual Studio where you 'Rebuild Solution' then 'Start without Debugging' to the Emulator to get the visuals up as normal - no fault here. However when you look at Unity and click on the 'Console' tab and the base of the editor you get this:-

Now I have a GameObject called 'TestCollection' which really is the OrigamiCollection of MicroSoft's Tutorial 101E. In my case, I left out the 'Spatial Sound' step as I did not want music in the background. To all practical extends my version of TestCollection mirrors that of the original. I dragged my newly formed C# script over the TestCollection gameobject so it would be included as a Component.

Add in to your class a yet-to-be-defined IList object which will be defined in Start()
static public IList dataset;

    void Start()
    {
        set_data_folder();
        dataset = new List<string>();
    }

Now, I will add some new 'Load and Save' routines that uses the Windows.Store namespace:-

    static async public void create_storage(string name)
    {
        try
        {
            writefile = await storageFolder.CreateFileAsync(name, CreationCollisionOption.OpenIfExists);

            if (!StorageApplicationPermissions.FutureAccessList.CheckAccess(writefile))
            {
                //datagramsocket.message_to_send = "Unable to access file: " + writefile.Path;
                return;
            }
            //datagramsocket.message_to_send = String.Format("The file '{0}' opened: ", writefile.Name);

        }
        catch (Exception ex)
        {
            writefile = null;
            // I/O errors are reported as exceptions.
            //datagramsocket.message_to_send = String.Format("Error creating file '{0}': {1}", name, ex.Message);
        }
    }
    static async public void read_storage(string name)
    {
        try
        {
            var item = await storageFolder.TryGetItemAsync(name);
            readfile = (item != null) ? (StorageFile)item : null;
        }
        catch (Exception e)
        {

        }

        if (readfile != null)
        {
            dataset = await FileIO.ReadLinesAsync(readfile);
        }
    }
    static async public void write_line(string textline)
    {
        string crlf = "" + (char)(13) + (char)(10);
        if (writefile == null)
        {
            create_storage(datascript);
        }
        if (writefile == null) return;
        await FileIO.AppendTextAsync(writefile, textline + crlf);
    }
    static public string save_file_to_permanent_store()
    {
        StorageApplicationPermissions.FutureAccessList.Clear();
        string writetoken = StorageApplicationPermissions.FutureAccessList.Add(writefile, writefile.Name);
        //datagramsocket.message_to_send = "Saved: " + writefile.Path + " token: " + writetoken;
        return writetoken;
    }

    static async public void read_lines()
    {
        if (readfile == null) return;
        dataset = await FileIO.ReadLinesAsync(readfile);
    }


Now save and go back to Unity then launch using Build Settings/Build. However please look at the errors this time:-

The last step just increased the errors reported by Unity. I then went to 'CursorMesh' which is a component of Cursor in the main Hierarchy in Unity and in the Inspector panel altered the scale to 2,2,2 for x,y,z respectively. Finally I was able to proceed through Build Settings into VS15 and after Rebuild Solution then clicking 'Start without debugging' I was able (without any errors reported) to get to the HoloLens Emulator that should me this view:-

I believe this must be because of the nature that 'async, await' that are all part of C#5 and Unity's own internal compiler currently only goes up to C#4.4. For me this is a bit of a problem and I must find other ways of filing safely without this bother. I have tried other methods but issues arise there too. I am willing to hear from anyone who can advise on this problem or has other ways of avoiding it in the first place.

Best Answer

Answers

  • Hello WheelChairMan, BUMP
    I too am having problems. Anyone have a solution yet? I want to do basic IO to a flat file. I'm using the emulator.

    Also, for some of my code that Unity complains about I'm #if blocking it out until I get to the compile phase in VS. Then I comment out a #define. This is required for a SocketIO library I'm using.

Sign In or Register to comment.