#Dude Im tired of scrolling up...
1 messages · Page 1 of 1 (latest)
yeah, so StatsManager is just this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class StatsManager
{
public string nom;
public int wp;
public float spe;
}
it's not attached since it's not monobehavior
Ok so it's just a struct data.
yeah
SaveStats[]?
that's pretty much the same thing, but to hold the data when it's being saved
I'm still confused. Are you not saving Stats off the memory? Like saving to a local drive?
Where does it gets it's inital information? Was it ever constructed?
I set its initial info in Unity
it's being saved to a file, yeah
this is my file-saving script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class SAVE: MonoBehaviour
{
public GameManager GAME;
public void Save()
{
GAME.Save();
string json = JsonUtility.ToJson(GAME);
File.WriteAllText(Application.dataPath + "/save.txt", json);
Debug.Log("Saved");
}
public void Load()
{
string json = File.ReadAllText(Application.dataPath + "/save.txt");
JsonUtility.FromJsonOverwrite(json,GAME);
GAME.Load();
Debug.Log("Loaded");
}
// Update is called once per frame
}
Whoa I'm so sorry to keep you waiting.
So many things going on in several threaded conversation!
yeah I can see lol
there are lots of questions around here
any tips? Because I'm stumped here
Give me a second
I'm quite under influence right now haha.
And were you able to read the save.txt file? Any data/information stored in there?
And lastly, after you load, were you able to output any data using Debug.Logs?
I strongly suspect that it can't parse json in txt file, but that's my doubt.
yeah, the json stuff is working perfectly well
the issue is the loading
and the saving
like, for some reason everything works fine until the first load
but afterwards it doesn't save again
I'm not sure why
Did anything happen in the Debug.Log()?
it did show the data on the json
Then I'm so confused, how can you tell if the data hasn't work, did you modify/change the data in between each load/save?
What if you're just overwritting "identical" data?
Like you just saved, then resaved it again without changing anything?
no, I did change the stats before saving again
so this is pretty much what happens:
- I modify the stats a bit
- I save
- I modify the stats a bit more
- I load
- it works and I'm back to my save
- I modify the stats again
- I save....but not really, for some reason it doesn't work anymore
- I load......but it doesn't work anymore either
Did you see if your data in the text file was changed around step 7?
just checked and it changes after step 5 but not after step 7
but it doesn't load from the data in the file in step 8 eiter
also I get this error when saving despite the Player object being DDOL
in 7
everything works fine until 4
so after the first load is the point where things go wrong
(also as you can see the player object is loaded in the script, so idk what unity is trying to say)
ok so I took out the whole thing with the player for the moment to check
Yeah, it's really hard to tell you exactly what's happening in your script. Usually more testing and further "Tracing" helps a lot. Just wish Unity implement a better breakpoint system..
so apparently, after step6, whenever I save instead of saving to the file the actual values, it's saving the initial values from the Unity editor
not entirely sure what's happeningg
Nevermind, I saw, it's not inheriting MonoBehaviour.
GameManager is fine.
I thought that your save data was inheriting MonoBehaviour. I would guess it reload it's inspector property on top of the serialized data.
Or better yet, how did you initialize them?
yeah, though the data on the GameManager object isn't affected anymore after the save
Did you try adding [SerializedField]?
where?
in your StatsManager
I used System.Serializable for the entire class
Right... Are you accessing the class through inspector?
yeah
wait, I found the issue
the SAVE script was getting destroyed each load
so it wasn't loading the GameManager
ah
Yeah