Forum rules - please read before posting.

Save Global Varaibles [Probably BUG]

When I work on Save - Load and Optimisation stuff.
I discovered a problem. For example;
I have a Global Var in Type of Vector 3 named Hat Position. The
Default value is (0,0,0).

After set the Hat Position through an ActionList to (0,200,0) and saved game after action list is ended. The Hat position is save as (0,0,0). I examine this data through Settings -> Manage Save-Game Files.

I thought tha might be a problem with my managers. I switch them to default managers and then try to recreate
this problems again and the Hat Position is saved as (0,0,0) again .

And then I recreate a new Project and add AC to project. Then I create a new Game through game wizard. But the problem still the same. The Hat Position still saved as (0,0,0).

Comments

  • edited January 2022

    I cannot recreate such an issue in the latest release. What is your AC version, and what platform are you building to?

    Are you relying on any custom save method? Let's see screenshots of the Action and variable involved.

    If you have Show realtime values? checked in the Variables Manager, and view the Variable's entry when you save, what value does it show?

    The saving of variable data occurs in the SaveSystem script's CreateVariablesData function. Look for the "case VariableType.Vector3" statement: if you place a Debug.Log in there, it may help reveal the issue.

  • edited January 2022

    What is your AC version, and what platform are you building to?

    AC: 1.73.0
    Unity: 2020.1.2f1
    Build: PC

    Are you relying on any custom save method? Let's see screenshots of the Action >and variable involved.

    I'am not use any custom save methodes. Just use Variables -> Set : Global Variables

  • Using a backup/duplicate project, does this occur for you in the latest release?

    Inside SaveSystem.cs, look for the following line inside its CreateVariablesData function:

    variablesString.Append (vector3Val);
    

    Underneath, paste the following:

    Debug.Log ("Vector variables " + _var.label + ", Value: " + _var.Vector3Value + ", Saved: " + vector3Val);
    

    That should report the variable when saved in the Console - does it show, and what does it say?

  • Vector variables Vector3 Test, Value: (54.0, 12.0, 0.0), Saved: 54,12,0

    But in Save-game Manager still show (0,0,0)

  • What was the result of testing the latest release, and what platform is active in your Build Settings?

    Place another Log just above the last line of the same function:

    Debug.Log (variablesString.ToString ());
    

    What does that show, stacktrace included?

  • What was the result of testing the latest release, and what platform is active in >your Build Settings?

    vector is (0,0,0) after save.

    What does that show, stacktrace included?

    Vector variables Test Vector3, Value: (54.0, 12.0, 0.0), Saved: 54,12,0
    UnityEngine.Debug:Log(Object)
    AC.SaveSystem:CreateVariablesData(List`1, Boolean, VariableLocation) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1580)
    AC.RuntimeVariables:SaveMainData(MainData) (at Assets/AdventureCreator/Scripts/Variables/RuntimeVariables.cs:211)
    AC.SaveOperation:SendSaveToFile() (at Assets/AdventureCreator/Scripts/Save system/SaveOperation.cs:141)
    AC.SaveOperation:BeginOperation(SaveData&, SaveFile) (at Assets/AdventureCreator/Scripts/Save system/SaveOperation.cs:81)
    AC.<PrepareSaveCoroutine>d__50:MoveNext() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:858)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.SaveSystem:SaveSaveGame(Int32, Boolean, String) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:801)
    AC.SaveSystem:SaveGame(Int32, Int32, Boolean, Boolean, String) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:783)
    AC.SaveFileManager:SaveFileGUI() (at Assets/AdventureCreator/Scripts/Managers/SaveFileManager.cs:315)
    AC.SaveFileManager:OnGUI() (at Assets/AdventureCreator/Scripts/Managers/SaveFileManager.cs:52)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    
    0:54,12,0
    UnityEngine.Debug:Log(Object)
    AC.SaveSystem:CreateVariablesData(List`1, Boolean, VariableLocation) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1581)
    AC.RuntimeVariables:SaveMainData(MainData) (at Assets/AdventureCreator/Scripts/Variables/RuntimeVariables.cs:211)
    AC.SaveOperation:SendSaveToFile() (at Assets/AdventureCreator/Scripts/Save system/SaveOperation.cs:141)
    AC.SaveOperation:BeginOperation(SaveData&, SaveFile) (at Assets/AdventureCreator/Scripts/Save system/SaveOperation.cs:81)
    AC.<PrepareSaveCoroutine>d__50:MoveNext() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:858)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.SaveSystem:SaveSaveGame(Int32, Boolean, String) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:801)
    AC.SaveSystem:SaveGame(Int32, Int32, Boolean, Boolean, String) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:783)
    AC.SaveFileManager:SaveFileGUI() (at Assets/AdventureCreator/Scripts/Managers/SaveFileManager.cs:315)
    AC.SaveFileManager:OnGUI() (at Assets/AdventureCreator/Scripts/Managers/SaveFileManager.cs:52)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    
    
  • Prepare a test scene that contains a Variable: Set Action that sets the variable, and check that saving the game in that scene afterwards causes the issue.

    Then, create a .unitypackage file of the scene, and your game's Managers. PM it to me, and I'll take a look.

  • Hi @ChrisIceBox!
    This is my first message here :) I've been using your wonderful plugin for 2 years now and have been searching (and finding) informations on the forum. Your work is remarkable!

    I have the exact same issue than @FelixGumenita. I would like to know if you (both of you) find a solution?

    Thx a lot :)

  • Welcome to the community, @Kinteros.

    The specific case in this thread fixed after v1.74.5. IIRC at least part of the issue was related to the Save-game File Manager displaying incorrect values.

    What are your AC/Unity versions and platform, and can you share some details about the issue, whether this affects all or only a specific variable, and what the save-data looks like in the Save-game File Manager?

  • Thx for your reply @ChrisIceBox :)

    I will try to explain.

    AC version : 1.80.5
    Unity version : 2021.3.29f1

    1. I use global variables to remember the player's position before exiting a scene, so that when I return to scene I can put the player back in the right place.
    2. Before leaving a scene, I set a Vector3 variable using Object > Record transform, Record player checked, Record Position to the right variable.
    3. I change scene. The variable in AC GAME EDITOR is correctly set.
    4. I save.
    5. I load the save.
    6. The variable is at 0,0,0.
    7. In the save file, the variable is set to 0,0,0.

    Some screens:
    The variable:

    The action before leaving the scene:

    I'm leaving the scene to go to another scene.
    The variable has been set to the correct value:

    I save :

    In the save file, the position is not recorded:

    Save manager settings:

    Am I doing something wrong?
    Do global variables register correctly in the backup? Or do I need to do something special for Vector3?

    Thank you very much :)

  • edited May 16

    This is just a hunch, but what is your OS' system language, and does it use commas instead of decumals for numbers, i.e. 1,5 instead of 1.5? I wonder if this is down to the way variable values are being parsed into the serializer.

  • You have the eyes of a lynx! Good one! You're good!
    Good guess, I'm French and I have WIN10 in french.

    Is it possible to force localization in Unity? I'm looking in the preferences or project settings but I can't find anything about it :(
    Looking around the forums, it's actually been a big problem for a lot of people since a 2018 version (it's global to Unity).
    https://forum.unity.com/threads/decimal-separator-randomly-becoming-something-that-looks-like-a-comma.257708/

    Do you force this type of format with CultureInfo? If that's already the case, there's something else that overrides it :/

    Do you have any other ideas for solving this problem? I'm running out.

    Thx

  • @ChrisIceBox nevermind, I pay more attention to forums and I've found a fix:

    I added this script to my assets and it fixes the dot/comma bug.

    using System.Globalization;
    using System.Threading;
    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    #if UNITY_EDITOR
    [InitializeOnLoad]
    public static class FixCultureEditor
    {
        static FixCultureEditor()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        }
    }
    #endif
    
    public static class FixCultureRuntime
    {
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
        static void FixCulture()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        }
    }
    

    Thank you so much for your very quick help !

    I can't wait to show you the game we're making. By the way, how do you manage the rights to use your plugin and the games you create with it? I remember your old site had a section on this, but I can't find it on the new version.

    Thanks a lot!

  • Script looks good, thanks for sharing.

    how do you manage the rights to use your plugin and the games you create with it?

    So long as you don't use the demo assets for your game, you're free to distribute AC-built games as you wish.

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.