So I’ve been having some issues. Everything here works perfectly well until after I load after the initial game load (whether it be due to using load or changing scenes)
Nothing gets saved or loaded after that load. The Save and Load scripts do get activated, but for some reason the Stats and Saved variables in the GameManager object don’t get changed anymore. Instead what is saved to the file is the initial values for StatsManager I set on the editor (and it doesn’t get loaded to the GameManager object either when I try to load).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager: MonoBehaviour
{
public Player play;
public static GameManager instance;
public Vector3 pos;
public StatsManager[] Stats;
public StatsManager[] Saved;
public int scene;
private void Awake()
{
scene = SceneManager.GetActiveScene().buildIndex;
}
public void Start()
{
//LoadParty();
if (instance == null)
{
DontDestroyOnLoad(this.gameObject);
instance = this;
Debug.Log("Don'tdestroy");
}
else if (instance != this)
{
Debug.Log("Destroy");
Destroy(this.gameObject);
}
}
public void Save()
{
//pos = play.SavPosition();
for (int i1 = 0; i1 < Stats.Length; i1++)
{
Debug.Log("Saving these stats1: " + Saved[i1].wp);
Saved[i1].nom = Stats[i1].nom;
Saved[i1].wp = Stats[i1].wp;
Saved[i1].spe = Stats[i1].spe;
Debug.Log("Saving these stats: "+ Saved[i1].wp);
}
}
public void Load()
{
SceneManager.LoadScene(scene);
Debug.Log("Quackity");
for (int i1 = 0; i1 < Stats.Length; i1++)
{
Stats[i1].nom=Saved[i1].nom;
Stats[i1].wp= Saved[i1].wp;
Stats[i1].spe= Saved[i1].spe;
}
//play.LoadPosition(pos);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class StatsManager
{
public string nom;
public int wp;
public float spe;
}