Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

WebGL saving/loading

Discussion in 'WebGL' started by Zebul, Apr 26, 2019.

  1. Zebul

    Zebul

    Joined:
    Jun 12, 2017
    Posts:
    3
    Hello!

    I'm quite new to the web player and javascript, so I've been stuck on a problem for some hours now and hope for some help...

    What I need is to be able to save/load and xml/json file from either the local pc storage/ cookies/ webserver.
    There is no restriction on the the method as long as it works as it is for a prototype. From my research it is either done using Php(which I have no experience with whatsoever) or an internal library in javascript .jslib

    The exact situation for people still reading is that the player/person has to be able to save the whole level he build and then be able to load it some other time. The deployment platform is GitHub Pages.

    I aready made the whole serialization, even tried uploading the xml/json file on the webserver and then trying to access it, but at this point I don't think I can work around the jslib or PHP so any help would be appreciated!!!
     
  2. Zebul

    Zebul

    Joined:
    Jun 12, 2017
    Posts:
    3
    Please help!
    Thanks in advance!
     
  3. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    167
    As you point you can serialize to json (use integrated serializer or jsonDotNet) and then make http call (use UnityWebRequest https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html ), which store this json to web server by means of PHP for example (store to file on disk, or to database). When you need to Load your saved json - then use another http call (UnityWebRequest) to download json (from file or database).

    Also you can use IndexedDB in browser for local store this serialized json. In this case you don't need a server and php (and server db). Instead use client. In this case jslib may help to store to IndexedDB (search this keyword). Remark - IndexedDB is bind to domain, i.e. you can't migrate from one to another domain without loss of IndexedDB, it's security restriction to store\read only your domain's data (may play a role in your case of GitHub, don't ever know). Also user will lose content when he lost access to the browser in which data is saved.

    As very simple example of local browser storage you can use integrated PlayerPrefs (https://docs.unity3d.com/ScriptReference/PlayerPrefs.html), which stores to IndexedDB, with some limitations (like store string value by string key, don't know is it limited by size etc).

    I can't provide any complete example, search yourself please.
     
    Last edited: Apr 28, 2019