Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Feb 26, 2019 at 08:18 AM by schnein2 for the following reason:

Other

avatar image
0
Question by schnein2 · Feb 12, 2019 at 04:01 PM · buildwebgljson

Reading .json file from WebGL build

Hello everyone,

I have a problem with reading a .json file from my WebGL build. I found following solutions on the internet:

  • https://stackoverflow.com/questions/43693213/application-streamingassetspath-and-webgl-build

  • https://forum.unity.com/threads/webgl-builds-and-streamingassetspath.366346/

and I tried to implement it into my own script.


In the following code all variables are global.

I call the coroutine from the Start() method:

 void Start() {
 filepath = System.IO.Path.Combine(Application.streamingAssetsPath, filename);
 StartCoroutine(LoadStreamingAsset());
 }

This is the coroutine:

     private IEnumerator LoadStreamingAsset()
     {
         if (filepath.Contains("://") || filepath.Contains(":///"))
         {
             WWW www = new WWW(filepath);
             yield return www;
             LoadContent(www.text);
         }
         else
             // read nothing or log error
     }

and I want to load the content into a List:

     private void LoadContent(string fileContent)
     {
         jsonFile = JsonUtility.FromJson<JsonFile>(fileContent);
         ContentToList();              
         StopAllCoroutines();     // don't know if this is necessary 
     }

I got numerous "memory access out of bounds" errors and sometimes the game would load (but without the content from the .json file). I guessed the coroutine would still be running so I used the "StopAllCoroutines()" method which solved the memory issues but the file still won't load. This is the first time I used coroutines in my game and I'm not sure if I'm doing the right thing here.


Am I correct that without the coroutine the filestream hasn't finished downloading while I try to load the content into the list? That was also a browser console error.


Thank you for your help!

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Marco-Trivellato · Feb 21, 2019 at 05:20 PM 0
Share

Are you sure the WWW succeeded in downloading the file?

avatar image schnein2 Marco-Trivellato · Feb 22, 2019 at 08:22 AM 0
Share

I managed to get the WWW part running and the file downloads! The code looks a little bit different but it works (thats all I'm concerned about now). I'm going to close this question. If you want any more information, let me know.

avatar image capu087 schnein2 · Aug 31, 2019 at 10:31 AM 0
Share

Hello, I have the same problem as you had. What did you changed to make the WWW part work?

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

116 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

WebGl build throw numbers (maybe assembly pointers) 0 Answers

Unity webGL build changes not reflecting,Unity webgl changes is not reflecting in build 1 Answer

WebGL and Access-Control-Allow-Origin 1 Answer

WebGL Build Error: IL2CPP error 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges