Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Saving data between webGL sessions and builds

A topic by TheDutchMagikarp created Oct 01, 2020 Views: 3,342 Replies: 1
Viewing posts 1 to 2
(+5)

Hi there!
I'm currently developing my game (with Unity) and for easy testing I am creating webGL builds to put on my page.
Between sessions, I need to store the audio settings and highscore of the player. I used to do this with playerprefs.
Playerprefs broke between different builds, which is far from optimal,  so I went to find a solution. On google, I found this old post.

The post explains why playerprefs doesn't work between builds, which is understandable. I created a small test project in which I save a value with the workaround provided by Beck and it worked! I was happy and started to rewrite the code for my main project.

Now when testing my main project, it doesn't work anymore?!

I won't ask for support with my code, because obviously that's not the goal here, but I am looking for solutions.
Is there a way to save data between Unity webGL sessions and build versions on itch?

(+12)

With some help from a friend on Discord, I found the solution!
For some reason the changes to the file system were flushed to the IndexedDB right away in my test project, while that wasn't the case in my main project. 

I read this link multiple times on my search, but always discarded it as not being the solution.

It was the solution.

All I had to do was adding 

    [DllImport("__Internal")]
    private static extern void JS_FileSystem_Sync();

to my code and then calling JS_FileSystem_Sync() after finishing up the writing.


I'm gonna leave this topic up in case someone ever runs into the same problem.
If a moderator decides that it's better to delete the post, feel free.
You can also lock it if you want, I won't be needing further assistance here.

This topic has been auto-archived and can no longer be posted in because there haven't been any posts in a while.