Is there a way to create a variable that doesn't get reset when exiting to the main menu? I'm working on a feature that displays a selection when the variable's value changes, but the variable always resets when returning to the main menu, so I can't implement this feature.
  • Have you got it set to a Global type? Sounds like you are using Local.
  • Yes, I made the variable global.
  • Starting a new game, loading a save game or exiting to the start menu will reset variables and use the Initial Variables set up in Game > Game Settings.

    You can e.g. use PlayerPrefs to store values outside the variable system - schematics have nodes to use/change them and all value type fields (e.g. for int/float values) can use them as well.

    Alternatively, you can try setting up an option in UI > Option Categories that's saved with the options file, but changing the variable would need to go through an options menu to save the change.
    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!
  • Oh smokes, just to jump on this as well, so I've got a town that grows over time using global variables to track town level. Will they be reset every time the game closes and a save is loaded?
  • Well, yeah - variables are saved with save games, i.e. when loading the game you'll have them back.
    They're not shared across different plays, e.g. each new game you start will have it's own variables.

    For persistent values you need to use PlayerPrefs.
    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!
Sign In or Register to comment.