Forum rules - please read before posting.

Global variable values not loading properly

I am having this very strange problem in my game and I was able to reproduce it on a minimal example:
We have 3 scenes - Loader, Scene 1 and Scene 2, all of them with GameEngine included.
Global variables: 0 TestBool initalizes to false, 1 TestInt initializes to 0.
Loader scene has OnStart action list - if Save slot 0 is empty, switch to Scene 1, otherwise load AutoSave.
Scene 1 has 2 hotspots -
A) switches to Scene 2 and
B) sets TestBool to true and TestInt to 2
Scene 2 has one hotspot that switches to Scene 1.
Scene 1 and Scene 2 both have OnStart action list that only saves game to Autosave.

I start up the game from Loader - switches to Scene 1 as expected. There I click the variable changing hotspot B) and after that hotspot A) leading to Scene 2. My variables are set to True and 2 as expected. I stop play mode.

I start the game up from Loader again - loads Scene 2 as expected. But the variables are back to their initial values.

I tried changing the save file format to json and got this: "runtimeVariablesData":"0:1|1:2" as I would expect. The behaviour was still the same.

What is wrong here? Did I miss something? AC version 1.72.4

Comments

  • Just going by your description, the variables should have loaded. There may be something more to it, however minor.

    Do you have this in a project you could PM me? You should be able to create a minimal .unitypackage file containing only the three scenes, your Managers, and any ActionList assets that may be involved - AC itself won't be necessary to include.

    I tried changing the save file format to json and got this: "runtimeVariablesData":"0:1|1:2" as I would expect.

    FWIW, it's also possible to read save file data by opening the Save File Manager from within the Settings Manager's Save game settings panel.

  • edited January 2021

    Ok, sent the project.
    Thanks for pointing me to the save manager. I see now that regardless of whether it's autosave or I save manually, the global variables still keep their initial values in the save when viewed via Save File manager.
    Interestlingly enough when JSON saves are enabled the Save File manager still shows the same data (initial values only) but savj files contain correct data.

    EDIT: on further observation I discovered that saving manually and then loading will load the variables correctly. Even loading the autosave manually, if done within the same game session, will load the variables correctly.

  • I tried my luck with debugger and found this bug in SaveSystem.cs:
    When loading to a scene different than the current one (which is always the case in my example) then in ReturnMainData () on line 503 the if condition becomes true. This results in an early return and InitAfterLoad() is never called as is probably the intention in ReturnMainData (). Calling InitAfterLoad() before the return appears to fix this problem for now.

    When this is done manually from the Load menu InitAfterLoad() gets called from MultiSceneChecker's Start() - I didn't dive deep enough to understand how or why is this different from loading via action list on start.

  • Thanks for the package - I've recreated the issue.

    It appears that this occurs because you're loading the save file in the same frame that the scene is initialising.

    I'll look into a fix as part of the next update, but in the meantime you should be able to remedy it by inserting an Engine: Wait Action for a brief pause before loading the Autosave.

  • edited January 2021

    Ok, I'll definitely give that a try, thank you.
    So far my solution via code edit (see my previous comment - added InitAfterLoad() right before line 514) seems to work and I didn't see anything that looks problematic in InitAfterLoad() - shall I be worried about some unexpected effects here?

  • Yes - it would be safer to wait for the official fix, but the Engine: Wait action should help in the meantime.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.