Forum rules - please read before posting.

Loads wrong scene

We have a major bug in our saving system. Loading a save file loads entirely the wrong scene sometimes. Sometimes it loads the correct scene, but the wrong camera and replays the starting cutscene when it was already finished in the save file (this is the OnStart cutscene, not the OnLoad cutscene . Only some of the Adventure Creator variables seem to reset to their saved values when loading a save file in the same scene.

«13

Comments

    • What are your AC / Unity versions?
    • What platform are you working on?
    • Is this occuring in builds, the Editor, or both?
    • Is this an issue with old saves, or are you able to reliably recreate the issue with new save files?
    • By "sometimes", do you mean the same file sometimes loads incorrectly, or some files always work while others always don't.

    Share screenshots of your Settings Manager's "Save game settings" and "Character settings" panels. If you have this issue in the Editor, open up the Save-file Manager from the first panel and view the raw save-data for a typical save. Share screenshots and I'll take a look as well.

    Only some of the Adventure Creator variables seem to reset to their saved values when loading a save file in the same scene.

    Of which type? Global, Local, or Component?

  • edited January 2023
    • What are your AC / Unity versions? AC 1.74.2, Unity 2020.3.27
    • What platform are you working on? So far this is happening in the editor and the Windows build
    • Is this an issue with old saves, or are you able to reliably recreate the issue with new save files? Because we're just testing the save system now it's all new saves
    • By "sometimes", do you mean the same file sometimes loads incorrectly, or some files always work while others always don't. Sorry, that was badly worded. The if the save loads to the wrong place, it loads that way consistantly. So we save in a street scene, but that save file will always load to the office scene, no matter what scene we load that save from. But some different save files WILL load the correct scene.

    All global.

    Forgot to mention we are also using Dialogue System and Steamworks. I've also got some unique Remember scripts.

  • Thank for the details. All scenes are listed in Unity's Build Settings, I take it.

    In a backup/duplicate project, import the latest AC release, run the Auto-add Save components to GameObjects operation, and then test out newly-created saves once done.

    If the issues remain, click Manage save-game files, select the save file that's causing the Street/Office scene and share screenshots of its data, together with your Build Settings window.

    Only some of the Adventure Creator variables seem to reset to their saved values when loading a save file in the same scene.

    Is this independent of which scene is loaded, and are the problematic variables the same each time?

  • Thanks, I'll do this and let you know.

    When I'm testing I'll make note of what variables are effected/not effected.

  • Unfortunately upgrading AC broke the project, we've got a lot of extensions to it now that are getting overwritten. I did try just running the Auto-add and it didn't break or fix anything with the variables. I now can not recreate the issue with the scene loading wrong, but the variable loading wrong is still an issue.

    Here are two save files - one where variable 23 LASActive should be false, and the next where it should be true. Loading either from the other will not update the variable, it will just stay however it was. Meanwhile, variable 18 Time updates just fine.

    https://blekkenhorst.ca/2021/wp-content/uploads/2023/01/PeoPoli_4.zip

  • Unfortunately upgrading AC broke the project, we've got a lot of extensions to it now that are getting overwritten.

    Is it possible those extensions are affecting the scene issue? Whenever possible, the best way to extend AC is through custom events.

    Here are two save files

    I can't work with the save-files without the associated project. If you use the Save-file Manager I mention above, however, you can share screenshots of the data involved. In particular, the "Global Variables" section in the "Main data" section for the two files involved.

    Are these variables linked to anything, e.g. Options Data or Custom Script?

  • The variables in question are not linked to the edits. There were a few (like the Highlight script) that have been edited by other departments.

    The only edits we have associated with the save system are the ones discussed here: https://adventurecreator.org/forum/discussion/12145/remember-whether-a-gameobject-is-enabled-when-save-loading#latest I've made another one based on RememberMultipleEnabled called RememberBrowserHistory which just remembers a list of strings rather than a list of gameobject's activations. I haven't noticed any issues with these, they work as expected. Here's the RememberBrowserHistory in case it's the culprit:

        using UnityEngine;
    using AC;
    using System.Collections;
    using System.Collections.Generic;
    
    public class RememberBrowserHistory : Remember
    {
        public List<WebPage> historyList;
        public List<string> historyListString;
    
        public List<WebPage> objectsToSave;
        public string listAsString;
        public int varID;
    
        public override string SaveData()
               {
               RememberBrowserHistoryData data = new RememberBrowserHistoryData();
                   data.objectID = constantID;
                   data.savePrevented = savePrevented;
    
    
                 data.history = new string[historyListString.Count];
                    for (int i = 0; i < historyListString.Count; i++)
                    {
                        data.history[i] = historyListString[i];
                    }
    
    
    
               return Serializer.SaveScriptData<RememberBrowserHistoryData>(data);
               }
    
               public override void LoadData(string stringData)
               {
    
            historyListString.Clear();
    
          RememberBrowserHistoryData data = Serializer.LoadScriptData<RememberBrowserHistoryData>(stringData);
                    if (data == null) { Debug.Log("data is null"); return; }
                        SavePrevented = data.savePrevented; if (savePrevented) return;
    
                       for (int i = 0; i < data.history.Length; i++)
                        {
                historyListString.Add(data.history[i]);
                        }
        }
    
    
    
        public void AddData(string newObjectToSave)
        {
            if (!historyListString.Contains(newObjectToSave))
                historyListString.Add(newObjectToSave);
        }
    
        public void ClearData()
        {
            historyListString.Clear();
        }
    
    
    
    }
    
    [System.Serializable]
    public class RememberBrowserHistoryData : RememberData
    {
    
        public string[] history;
    
        public RememberBrowserHistoryData() { }
    
    }
    

    and the editor

    using UnityEngine;
    using UnityEditor;
    using AC;
    using System.Collections.Generic;
    
    [CustomEditor(typeof(RememberBrowserHistory), true)]
    public class RememberBrowserHistoryEditor : ConstantIDEditor
    {
        public string listAsString;
        public int varID;
        public List<string> historyListString;
        public override void OnInspectorGUI()
        {
            RememberBrowserHistory _target = (RememberBrowserHistory)target;
            int numToSave = _target.objectsToSave.Count;
            numToSave = EditorGUILayout.DelayedIntField("# objects to save:", numToSave);
    
            int numToSaveString = _target.historyListString.Count;
            numToSaveString = EditorGUILayout.DelayedIntField("# strings to save:", numToSaveString);
    
    
    
            if (numToSave != _target.objectsToSave.Count)
            {
                List<WebPage> backup = _target.objectsToSave;
                //_target.objectsToSave = new GameObject[numToSave];
                for (int i = 0; i < Mathf.Min(numToSave, backup.Count); i++)
                {
                    _target.objectsToSave[i] = backup[i];
                }
            }
    
            for (int i = 0; i < _target.objectsToSave.Count; i++)
            {
                _target.objectsToSave[i] = (WebPage)EditorGUILayout.ObjectField("Object #" + i + ":", _target.objectsToSave[i], typeof(WebPage), true);
            }
    
            for (int i = 0; i < _target.historyListString.Count; i++)
            {
                _target.historyListString[i] = (string)EditorGUILayout.TextField("Visited: ", _target.historyListString[i]);
                    //.DelayedTextField("String #" + i + ":", _target.historyListString[i], typeof(string), true);
            }
    
            SharedGUI();
        }
    
    }
    

    This is the editor when I save the game, and LASActive is false:

    Then I play until LASActive becomes true, load the save - the save still says False but the AC Game Editor shows true.

  • Thanks for the details. The script you've posted shouldn't factor into this.

    Just to rule out this not being a case of the variable being set to True (rather than not updated at all), what is the behaviour of setting it back to False before loading the save file as above? Does it now remain as False, or revert back to True?

    As I can't recreate the behaviour on my end, it may have to be a case of you PMing me a project .zip that I can access to see the problem for myself.

  • Good call - I tested it, and it IS changing the variable to the opposite of what it's supposed to be, not just leaving it at whatever it's set to.

    I will zip and send you the project.

    One way to recreate:

    • Open Hub_Apartment
    • Set Global Variable 19 'Level' to L3
    • Set GV 18 'Time' to Night
    • Play, save first save slot as soon as the cut scene ends. (GV 23 'LASActive' is false, no icon in corner.)
    • Click on couch. (GV 23 'LASActive' changes to true, icon appears in top right corner.)
    • Save in second save slot.
    • Load first save slot
      *Result: LASActive is set to true (even if you manually set it to false while sitting on the couch.)

    The reverse also works.

    • Navigate to couch, save. (LASActive is true.)
    • Restart level, load couch save (LASActive will be false, even if it was set to true before.)

    If it helps, another way to reproduce in a different scene:
    * Load Hub_Street
    * Set Global Variable 19 'Level' to L2
    * Set GV 18 'Time' to Morning
    * Play, save first save slot as soon as the cut scene ends. (GV 23 'LASActive' is false, no icon in corner.)
    * Navigate to the bus stop/bus
    * LASActive will become true after cut scene
    * Set to false
    * Load the save,
    * Result: LAS has set to true

  • I found a way to reproduce the original issue - loading a save from the same scene loads properly - the camera is in the right place. But loading a save from another scene triggers the OnStart cutscene instead.

    • Load Hub_Office
    • Set Global Variable 19 'Level' to L1
    • Set GV 18 'Time' to Morning
    • Play, go up the elevator, save first save slot as soon as the cut scene ends.
    • Play through the scene until it switches to Hub_Apartment
    • Load the save,
    • Result: You are back downstairs and the first cutscene is playing again
  • Thanks for the steps, I'll follow them and see.

  • This occurs because your loading scene is configured in the Settings Manager, but the scene itself is not listed in the Build Settings.

  • I'm sorry I never responded to this! I turned off the loading screen (and left the loadingscreen in the build settings just in case.) This did fix the issue with it reloading the opening cut scene, but there are still problems. Is mostly seems to be an issue with the street scene - sometimes a save that should be Hub_Street will load Hub_Office instead, and will consistantly load Hub_Office instead.

    Also, how do I create the first autosave file? There is only an option for "Overwrite existing file" and this doesn't seem to initially create the autosave.

  • Is mostly seems to be an issue with the street scene - sometimes a save that should be Hub_Street will load Hub_Office instead, and will consistantly load Hub_Office instead.

    If you can PM me an updated project with steps to reliably recreate the issue, I can look into it.

    Also, how do I create the first autosave file? There is only an option for "Overwrite existing file" and this doesn't seem to initially create the autosave.

    If "Overwrite existing file" is set to overwrite the Autosave, but no Autosave exists, it'll create one automatically.

  • It's weirdly not creating one in the first scene of the game, but it does make one in a later scene.

    I deleted all the save files to figure out how to recreate the issues and of course it's not recreating - I'm doing a LOT of save testing in the next week, I suspect it may surface.

    The save buttons allow me to use an "actionlist on click" - is there anything like that for the load buttons? It would be nice to fade out the scene while the save file is loading.

  • The save buttons allow me to use an "actionlist on click" - is there anything like that for the load buttons?

    Yes - a SavesList element set to "Load" will have a similar ActionLists asset field.

    In the case of loading, however, you'll likely want to run an ActionList that fades-out before the actual loading occurs.

    To do this, uncheck Load when click on?, and then assign an ActionList that fades the camera out in the ActionList when click field. If this ActionList has an Integer parameter defined, it can be set by the element automatically to the clicked save slot - which you can then use to load the game manually with the Save: Save or load Action.

  • Hmm, I must have misunderstood a step, now clicking on the button does nothing except highlight the button.

    Here is what I have:

    (I am using a Unity Prefab, so all the buttons are listed as being missing when I am not in prefab mode but they have always worked before, so I don't THINK that is the issue?)

  • Oh my goodness this game is so haunted. Seconds after I posted this I tried loading a save again and the loading works, but the scene does not fade out and I suspect loading is taking a touch longer.

  • I didn't touch anything, I've been testing other things with the save system, but now
    for some reason fading out is working but I'm getting this error:

    NullReferenceException: Object reference not set to an instance of an object
    AC.GVar.set_FloatValue (System.Single value) (at Assets/AdventureCreator/Scripts/Variables/GVar.cs:766)
    AC.GlobalVariables.SetFloatValue (System.Int32 _id, System.Single _value, System.Boolean synchronise) (at Assets/AdventureCreator/Scripts/Static/GlobalVariables.cs:327)
    TimePlayedCalculator.Update () (at Assets/TimePlayedCalculator.cs:43)

    TimePlayerCalculator line 43 is just
    AC.GlobalVariables.SetFloatValue(35, startTime);

    It's not even the first GVar set in the update loop.

  • for some reason fading out is working but I'm getting this error:

    What is your AC version now? This may be addressed in the latest release.

    the scene does not fade out and I suspect loading is taking a touch longer.

    You'll need to check Wait until finish? in the Camera: Fade Action to ensure the transition is shown in full before the loading process kicks in.

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.