#Dude Im tired of scrolling up...

1 messages · Page 1 of 1 (latest)

tired garden
#

Ok that makes this whole thing confusing

#

StatsManager is on GameManager?

tame gulch
#

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

tired garden
#

Ok so it's just a struct data.

tame gulch
#

yeah

tired garden
#

SaveStats[]?

tame gulch
#

that's pretty much the same thing, but to hold the data when it's being saved

tired garden
#

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?

tame gulch
#

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

}
tired garden
#

Whoa I'm so sorry to keep you waiting.

#

So many things going on in several threaded conversation!

tame gulch
#

yeah I can see lol

#

there are lots of questions around here

#

any tips? Because I'm stumped here

tired garden
#

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.

tame gulch
#

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

tired garden
#

Did anything happen in the Debug.Log()?

tame gulch
#

it did show the data on the json

tired garden
#

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?

tame gulch
#

no, I did change the stats before saving again

#

so this is pretty much what happens:

  1. I modify the stats a bit
  2. I save
  3. I modify the stats a bit more
  4. I load
  5. it works and I'm back to my save
  6. I modify the stats again
  7. I save....but not really, for some reason it doesn't work anymore
  8. I load......but it doesn't work anymore either
tired garden
#

Did you see if your data in the text file was changed around step 7?

tame gulch
#

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

tired garden
#

Interesting...

#

When did that error appear? In between 2 or 3?

tame gulch
#

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

tired garden
#

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..

tame gulch
#

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

tired garden
#

That's interesting..

#

Wait, is it inheriting monobehavior?

tame gulch
#

which

#

statsmanager or GameManager

#

@tired garden

tired garden
#

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?

tame gulch
#

yeah, though the data on the GameManager object isn't affected anymore after the save

tired garden
#

Did you try adding [SerializedField]?

tame gulch
#

where?

tired garden
#

in your StatsManager

tame gulch
#

I used System.Serializable for the entire class

tired garden
#

Right... Are you accessing the class through inspector?

tame gulch
#

yeah

tired garden
#

Try not do that?

#

Have the class constructed at runtime, with predefined value.

tame gulch
#

wait, I found the issue

#

the SAVE script was getting destroyed each load

#

so it wasn't loading the GameManager

tired garden
#

ah

tame gulch
#

Yeah