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. Dismiss Notice

PersistentDataPath returns different paths for differet builds

Discussion in 'WebGL' started by metinevren, Apr 14, 2018.

  1. metinevren

    metinevren

    Joined:
    May 17, 2014
    Posts:
    28
    When building with Unity 5.4.0f3 my game returns persistentDataPath as "/idbfs" but the builds I make with 2017.3.1f1 return different paths like "/idbfs/faaebcb....". And it's a different path in each build.
    Is this a bug? Shouldn't it all return "idbfs" ? What do I need to do?
    In the screenshot you can see the different SaveGame.dat files created by each build, because they all use different persistentDataPaths.

     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    In 2017, the persistentDataPath name contains a hash so that you can host multiple games at the same url without conflict. The hash is computed based on the url of the build json file.
     
    Last edited: Apr 16, 2018
  3. metinevren

    metinevren

    Joined:
    May 17, 2014
    Posts:
    28
    This isn't referred in the documentation at all, and it's a serious issue because the savegame file cannot be found by the newer version of the game.
    How can I overcome this issue? Would it be safe to directly use "/idbfs/MyGameName/SaveGame.dat" ?
     
  4. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Let me clarify:
    - It is expected that 2017.3.1f saves at a different location than 5.4.0f3.
    - Now, the indexedDB path is contains a hash, however, it's not supposed to change between builds.

    Bases on your screenshot, I see 3 different hashes, which is not expected. If this is what you are seeing that might be a bug.
    Unless, you uploaded different projects to the same domain, then it is expected and what you see is a saved game for each project.

    Does this make sense?
     
  5. metinevren

    metinevren

    Joined:
    May 17, 2014
    Posts:
    28
    It's the same project, yes it is creating different path each builds. That's what I'm saying.
    I sent a bug report, they said they can't reproduce it, I answered back to know what is wrong, they stopped answering.


    How is this hash determined? If I decide to change my project name, would it change it?
     
  6. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    what's the bug number?


    it's computed based on page url. We strip the html file name and compute the hash. So, changing the project name should not affect it.
     
  7. metinevren

    metinevren

    Joined:
    May 17, 2014
    Posts:
    28
    Is the url you are speaking of Application.dataPath? If that is the case, I've been uploading my game to itch.io as zip files. So each of them is contained in a different random path like //v6p9d9t4.ssl.hwcdn.net/html/837918/MyGamev1/index.html. So that must be the reason I got different path names each time. (although the page url I visit to play the game is "http: //MyNameHere.itch.io/MyGame", so that url is constant between builds.

    So in this case, my next question is: In this situation, is it possible to use the same save file with different versions of my game uploaded? Can I strip the hash part from persistentDataPath and use it as "idbfs/MyGame"? Would it be safe thing to do?
     
    Last edited: Apr 23, 2018
  8. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    Just wonder how to get the names of the IndexedDB database and object store?
    I need to put some data from pure JS before Unity starts, and later load it from the game script.
     
  9. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    Well, already found, database is "idbfs/" and store is MD5("proto://path.to.the.project")
     
  10. SirPsychoBexy

    SirPsychoBexy

    Joined:
    Dec 2, 2017
    Posts:
    2
    Hi, I'm having exactly the same problem as the OP. Is there a suggested workaround if different urls can't be avoided if that's the case on itch?
     
  11. pndeveloper

    pndeveloper

    Joined:
    Dec 7, 2015
    Posts:
    29
    This also appears to be a problem for Unity WebGL games on Facebook when using Facebook's web hosting for games (https://developers.facebook.com/docs/games/services/contenthosting/). Every time a new build is posted there's a change in the URL which results in a new hash for the idbfs path. It would be nice if Unity provided an option to set that path manually or a way to override it...
     
  12. Diego_Escobar

    Diego_Escobar

    Joined:
    Nov 18, 2019
    Posts:
    1
    this is still an issue? i mean, there is some way to store data/ persist data in a game on Itch?? tx
     
  13. SirPsychoBexy

    SirPsychoBexy

    Joined:
    Dec 2, 2017
    Posts:
    2
    Haven't looked at this stuff in a while but I'll copy and paste my workaround from here: https://itch.io/t/140214/persistent-data-in-updatable-webgl-games

    I've managed to work around this by saving to/loading from "idbfs/GameName" rather than Application.persistentDataPath in WebGL builds. I saw metinevren suggested that here too: https://forum.unity.com/threads/persistentdatapath-returns-different-paths-for-d...

    HOWEVER, PlayerPrefs and a bunch of other unity stuff still use the persistentDataPath (eg "/idbfs/b647bc5784577....".) and I'm not sure how to change that. I'm not using PlayerPrefs so it's not an issue for me.

    Also don't know if this workaround is icky for other reasons. But I can now upload new builds as much as I like and my savegame persists!


    Hope this helps!