Search Unity

Resolved Saved Variables Not Saving After Quit on Build

Discussion in 'Visual Scripting' started by Private_StrayCat, Sep 9, 2023.

  1. Private_StrayCat

    Private_StrayCat

    Joined:
    Sep 9, 2023
    Posts:
    6
    Hello, I have been working on my first game for some time now and have hit a bit of a wall with saving, I've been trying to find out how to get my saved variables to actually save, they seem to work just fine going between different scenes, but not so much when it comes to actually closing the game and re-opening it. I've heard a bit of mention about this "Save Variables" node, which I have appended to a save script that runs every time the menu scene is entered. This is the script :
    Every other script that I have that uses the set saved variable node does not have the save variables in them.
     
  2. emilian-s

    emilian-s

    Joined:
    May 11, 2014
    Posts:
    19
    Hello.

    Please add some logs in graph, and more details about the UVS version you are using.

    upload_2023-9-10_20-52-11.png

    As you can see, in first run the log shows the initial value, and in the second run the log shows the saved value.

    Why do you say is not working for you?
     
    Private_StrayCat likes this.
  3. Private_StrayCat

    Private_StrayCat

    Joined:
    Sep 9, 2023
    Posts:
    6
    It seems to work just fine when I switch between scenes, but it doesn't save if I exit the program.
     
  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,072
    On Start triggers when you enter the scene once, it does not trigger on application exit. Just save the variables On Application Quit event.
     
  5. Private_StrayCat

    Private_StrayCat

    Joined:
    Sep 9, 2023
    Posts:
    6
    Gave it a shot, still doesn't quite seem to work
     
  6. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,072
    Perhaps also try OnDisable or OnDestroy. Maybe saved vars system is incompatible with On App Quit event since objects get disabled and destroyed on app quit.

    You could also try delaying the flow in Start. Perhaps there's some issue with execution order, so delaying the flow by a frame could solve that.

    Assuming none of the above works, my guess would be that you're setting the saved variables elsewhere in the initial start scene.
     
    Last edited: Sep 11, 2023
  7. Private_StrayCat

    Private_StrayCat

    Joined:
    Sep 9, 2023
    Posts:
    6
    Just found this in the console upload_2023-9-12_18-31-21.png
     
  8. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,072
    PlayerPrefs have very limited type support. Generally string, ints and floats are only accepted. Are you trying to save some other type?
     
  9. Private_StrayCat

    Private_StrayCat

    Joined:
    Sep 9, 2023
    Posts:
    6
    hmmm, are lists of bools accepted?
     
  10. Private_StrayCat

    Private_StrayCat

    Joined:
    Sep 9, 2023
    Posts:
    6
    Just figured it out, it was a list of materials that was causing the issue, thank you very much sir!
     
  11. maxiska2009

    maxiska2009

    Joined:
    Aug 27, 2021
    Posts:
    7
    Hello. I'm facing a similar problem. I use additive scene loading.

    So that the player does not look at the frozen screen when loading the next heavy scene - I load the loader scene to transition between the main scenes, which contains only one scenario - it additively loads the next scene, while showing animation. When the scene is ready to run, I perform Allow scene activation.

    If the player EXITS the game at the moment of additive loading of the scene, VS does not record the saved variables. And when you first start the game the next time - VS uses the saved variables from the moment when it was able to be overwritten. Sometimes it throws the player back several levels!

    I think the problem is that at the moment the player exits the game - there are two scenes in the game at once (one is a loader, the second is loaded additively) - and VS does not know how to save variables correctly and does not do it.

    The main question. How to FORCE save variables from time to time?

    "On application quit, pause" and next- player.prefs save variables d'ont work

    !!!

    I'm very sorry.

    The "save variables" node solved all my problems!

    I didn't know about its existence and tried to write down every saved variable forcibly - but it didn't help.

    By adding this node, everything began to be recorded!

    Just in case, I put the script in "dont destroy on load"
     
    Last edited: Oct 16, 2023