Delete save game resource

Godot Version

4.2.2

Question

On a Game Over I am deleting saved game data :

private void DeleteSaveData()
{
	if (ResourceLoader.Exists(Main.SavePath))
	{
		DirAccess.RemoveAbsolute(Main.SavePath);
	}
}

Then i reload the current scene, and after that I am trying to load game data (in case it was not a Game Over:

private void LoadGame()
{
	if (ResourceLoader.Exists(Main.SavePath))
	{
		data = ResourceLoader.Load<PlayerData>(Main.SavePath);
	}
}

In this case the resource should NOT exist and therefore continue like a new game.
But the resource is still there and therefore the functionality is broken.
I suspect that DirAccess.RemoveAbsolute is using async code under the hood, but I cannot await this method.
Any suggestions?

obraz
save Error in variable and print in console if not “OK”,

data = ResourceLoader.Load<PlayerData>(Main.SavePath);

you needed disable cache_mode,
you can try wait for ResourceLoader.Exists to be false.
You could reset data instead remove file.

As @Moreus said the problem was cache.

By using CacheMode.Ignore it fixed the issure.

private void LoadGame()
{
	if (ResourceLoader.Exists(Main.SavePath))
	{
		data = ResourceLoader.Load<PlayerData>(Main.SavePath, null, ResourceLoader.CacheMode.Ignore);
	}
}
1 Like