ctoia
New Member
Posts: 2
|
Post by ctoia on Aug 21, 2023 21:40:24 GMT
I've got overwrite if exists ticked and it works very intermittently (most of the time it doesnt work). The database is being copied back from the working path to the project path when exiting play mode.
My issue is that the database is being copied back without issue when exiting play mode but it isn't being copied into the working path when clicking play. It does work every time if I do something to the database (like just a simple SELECT query) before clicking play. It feels like some sort of cache issue.
Any idea how to get this to overwrite every time? Thanks
|
|
ctoia
New Member
Posts: 2
|
Post by ctoia on Aug 21, 2023 21:54:36 GMT
Okay I fixed this by disregarding the Overwrite if Exists functionality of the manager. Instead, I use this script now:
using UnityEngine;
using UnityEditor;
using System.IO;
[InitializeOnLoad]
public class UpdateProjectDatabase
{
const string WorkingDatabaseName = "game.bytes";
const string ProjectDatabaseName = "game.bytes";
static UpdateProjectDatabase()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}
static void Start()
{
var workingPath = Path.Combine(Application.persistentDataPath, WorkingDatabaseName);
var projectPath = Path.Combine(Application.dataPath, ProjectDatabaseName);
// Check if the file exists at the project path before copying
if (File.Exists(projectPath))
{
File.Copy(projectPath, workingPath, true);
}
else
{
Debug.LogError($"File does not exist at {projectPath}");
}
}
static void Quit()
{
//ChunkManager.Instance.UnloadAllChunks();
var workingPath = Path.Combine(Application.persistentDataPath, WorkingDatabaseName);
var projectPath = Path.Combine(Application.dataPath, ProjectDatabaseName);
File.Copy(workingPath, projectPath, true);
}
static void OnPlayModeStateChanged(PlayModeStateChange stateChange)
{
if (stateChange == PlayModeStateChange.EnteredPlayMode)
{
Start(); // Copy the file when entering play mode
}
else if (stateChange == PlayModeStateChange.ExitingPlayMode)
{
Quit(); // Existing behavior when exiting play mode
}
}
}
|
|
|
Post by echo17 on Aug 22, 2023 8:42:06 GMT
The working database shouldn't copy back to the project database unless you have some custom code that is doing this. The copy process in SimpleSQL is one-way: from project to working.
Not sure why you would experience intermittent copying, unless perhaps you have the database open in an external application (putting a lock on the file)? I'd have to see your project to try to reproduce since I cannot get this functionality from my own setup.
In any case, I'm glad you found a solution that works for you!
|
|