edited November 25 in ORK Support
Hiya!

I’m having trouble with Makinom variables not resetting correctly when switching between save files. When I load the first save file using a custom loading screen, everything works fine. However, if I switch to a second save file during the same session, the variables (e.g., CurrentDay, CurrentMonth) remain stuck on the first save file’s values. Restarting the game resolves the issue, and the second save file loads correctly.

I’m also trying to figure out how to detect when a new save file is being loaded, rather than just a regular scene transition. I think this could help ensure the variables are refreshed properly.

Any advice on how to handle this, especially with persistent objects like my Day Night Cycle that use DontDestroyOnLoad?

Thanks in advance!

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;

public class SceneLoader : MonoBehaviour
{
[SerializeField]
private TextMeshProUGUI loadingText = null;

private static string sceneToLoadFromOrk = null;
private bool loading = false;

#region ORK static methods
public static void LoadScene(string sceneName, LoadSceneMode mode)
{
HandleLoadScene(sceneName);
}

public static void LoadSceneAsync(string sceneName, LoadSceneMode mode)
{
HandleLoadScene(sceneName);
}

private static void HandleLoadScene(string sceneName)
{
sceneToLoadFromOrk = sceneName;
SceneManager.LoadScene("LoadingScreen", LoadSceneMode.Single);
}

#endregion

private void Start()
{
StartCoroutine(LoadORKScene());
}

IEnumerator LoadORKScene()
{
loading = true;
var ao = SceneManager.LoadSceneAsync(sceneToLoadFromOrk);
ao.allowSceneActivation = false; // Wait until loading reaches 100%

// Wait for the scene to load
while (!ao.isDone)
{
// When loading is complete, activate the scene
if (ao.progress >= 0.9f)
{
ao.allowSceneActivation = true;
}

yield return null;
}
}
}
Post edited by Anoo on
  • Maki.SaveGame.IsLoading should be true while loading the game.

    The variables being stuck, I'd guess that they're set after the variables are already loaded - e.g. in case they come from some still running schematic or other code (like a 3rd party day-night-cycle asset), that might still set it while loading.

    Handling your persistent objects depends on how they're used, e.g. if they need to do stuff when starting or stopping the game, you can register to event handlers in Maki.Game to get notified of starting or stopping the game (e.g. Maki.Game.StopGameCalled).
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Got it working! thanks
Sign In or Register to comment.