Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Saving game data for WebGL

Discussion in 'Scripting' started by PlazmaInteractive, Sep 28, 2016.

  1. PlazmaInteractive

    PlazmaInteractive

    Joined:
    Aug 8, 2016
    Posts:
    114
    Hey guys! As I'm getting closer and closer to finishing my first game, I'm now focusing a bit more on other parts of my project and that is saving game datas. I've researched a bit in the last couple of weeks on this and has come across some answers but I want to know which one should I choose. As I'm very new at this kind of things, it'll be best if you explain it in a basic way :)

    So, my plan is to upload my games to Kongregate and I'm also interested with GameJolt too. As I already told you before, I have found some answers and the first one is PlayerPrefs. I haven't learned PlayerPrefs extensively as of now (plan to do so) but I do know a bit about it and so far, it seems to be the promising one. While it is currently the one I'm going for, I've seen other threads that said PlayerPrefs is not working or something so I've come here to find out more. Will PlayerPrefs work on sites such as Kongregate/GameJolt?

    My second option is using server-side programming and MySQL which is totally new to me. I've come across a site named EasyPHP and phpMyAdmin and wondered if that will work for saving data in WebGL games. Also, I need to know if using this option is necessary for what I'm achieving or if it isn't needed as there's PlayerPrefs, though I will definitely study this because it seems useful in the future.

    Thanks!
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    PlayerPrefs doesn't work in webGL on any website that host your game in an iFrame. This includes Facebook and (last I heard) also Kongregate. I'm not familiar with GameJolt.

    We use a free backend service instead for our data.
    There are several. The two I recommend is either Playfab or Heroic Labs as they tend to have the best free plans.
     
  3. CrymX

    CrymX

    Joined:
    Feb 16, 2015
    Posts:
    179
    PlayerPrefs on webGL works for me in google chrome (not tested on other browser) it use the browser storage and can be cleared at any moment
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    You've tested this on something like Facebook? Because that wasn't the case when we originally released our game. We found that Playerprefs saved data only for a single session. If you closed out the browser and reloaded, your data would be gone.

    If you are not in an iFrame, PlayerPrefs is suppose to work just fine. Facebook still puts your game in an iFrame. Kongregate I haven't used, but I know when I was doing research before, it had the same issue.
     
  5. CrymX

    CrymX

    Joined:
    Feb 16, 2015
    Posts:
    179
  6. CrymX

    CrymX

    Joined:
    Feb 16, 2015
    Posts:
    179
  7. PlazmaInteractive

    PlazmaInteractive

    Joined:
    Aug 8, 2016
    Posts:
    114
    Thanks for the quick replies guys. So about that backend service, it seems interesting! From the small research so far, it seems like at least with PlayFab, that it'll work with Kongregate. Haven't searched for other sites but I'll keep researching.

    About PlayerPrefs, it seems like majority of developers in Kongregate says PlayerPrefs doesn't work, mostly due to the fact that Kongregate has an iFrame. I'll be waiting for more answers though.
     
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    I know what the docs say. But this is not what happens on Facebook. Trust me, we wrestled with it. Searches on the issue report the problem for Facebook and Kongregate. Your link isn't a Facebook game or a Kongregate game? That is why I said it needs to be tested on those two.

    @PlazmaInteractive I would say before you count on PlayerPrefs on webGL, you test it on whatever service you are releasing it on, because I can tell you for certain from testing that it did not work for us on Facebook, which is why we use a backend service.

    And yes, your research on people saying it doesn't work on Kongregate because of iFrame is the same thing we ran into for Facebook.
     
    CrymX likes this.
  9. CrymX

    CrymX

    Joined:
    Feb 16, 2015
    Posts:
    179
    I have read to fast, my game is not working on iframe
     
  10. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    @PlazmaInteractive
    Just to add, I don't know if Kongregate can be implemented on mobile, but if you plan to do a webGL and mobile build of your game, a backend service would be better as you can then get your data from multiple build targets. So a player could play your webGL game, then when they are on the go, log in and play on your mobile game, picking up where they left off. Or for that fact, even if they switch computers. This wouldn't work with playerprefs, even if they did work.
     
    CrymX likes this.
  11. PlazmaInteractive

    PlazmaInteractive

    Joined:
    Aug 8, 2016
    Posts:
    114
    Oh, that's excellent then! My current option is definitely the backend service but I'll wait a bit more before I decide my final answer. Still waiting for answers on server side programming and MySQL...
     
  12. BytesCrafter

    BytesCrafter

    Joined:
    Apr 16, 2016
    Posts:
    8
    Hey guys, you can do that on PHP MySQL Database. Just like I did. Hopefully this helps, Its about 8 parts, the first part will be a demo of my implementation php mysql to unity. Please do remember that the data transfer, is not local. Local to free Server and vice versa. hosted in a free server no money needed. as an indie game developer, cash is a problem. :D
    .
     
  13. nateonus

    nateonus

    Joined:
    Mar 20, 2018
    Posts:
    3
    I created a free-to-use plugin for anyone wanting to save/download a generic file in WebGL. It works seamlessly with all major browsers and operating systems, and is as simple as calling 'WebGLFileSaver.SaveFile()'.

    Get it here: https://github.com/nateonusapps/WebGLFileSaverForUnity
     
  14. papounet94

    papounet94

    Joined:
    Oct 5, 2017
    Posts:
    1
    Hi Nateonus,

    Forgive me is my question seems dumb, but how do I use this plugin?
    Should I add it to my browser? To Unity? And How? I am lost at the moment.

    Thanks for your answer.
    Christian
     
  15. mcanty55

    mcanty55

    Joined:
    Apr 17, 2014
    Posts:
    19
    nateonus,

    Does this also have a read file method?

    v/r