- Home /
GPGS - How to check if a Saved Game file exists?
I'm planning to use Google Play Game Services plugin's "Saved Games" feature for my online game to save in-game currency. The file name will be an hard-coded constant for everybody. So, how can i check if a Saved Game file exists or not?
Sound more like a question specific to GPGS rather than C# or Unity. For System.IO, there is File.Exists(), so I assume there must be something similar.
Well, their unity plugin's documentation is very poor, actually they should have thought this, unity is a huge community. Anyways, i'm trying to figure this out by fetching all saved games and checking the returning list.
Answer by CyanSprite · Aug 17, 2016 at 05:53 AM
@s-at-c have you tried:
private static void OnSavedGameDataRead(SavedGameRequestStatus status, byte[] data){
bool fileNeverWritten = data.Length == 0;
}
This works for me on first time setup type things, then I write data... If you are creating the save file, then not writing data and then checking it, I'm not sure if it will work, I will test soon and update you.
if there is no save file to read, how can this method be called? it doesn't go further than calling open method. checked that experimentally
In Google game services cloud saving you always have to open a file before attempting to save. Apparently if you try to read it right after opening without even saving, the reading call succeeds and returns a 0 sized byte array.
I just tried this and it works. This is the correct answer. As for committing an update of size 0 and checking afterwards I didn't test it either and have no idea if this will work either.