Forum rules - please read before posting.

Save game issue only on iOS

edited February 2021 in Technical Q&A

Hey guys,

I am currently on the Alpha milestone for an adventure game targeting both platforms (Android and iOS) . There are multiple savepoints (Autosave only) added throughout the game. Until now we had been only deploying android builds and the save works perfectly on an android device but only when we deployed an iOS build did we come to know it did not work. After looking through the forum, there was a discussion related to the topic and the solution was to switch to (Save in Json format experimental) in the AC settings which I did but now the issue is that the save works properly for some objects that have multiple remember scripts but not all. I'm afraid I might have to go back and separate the objects so that there is only one remember on them at any given point to have this work. Any fix for this would be really helpful.

Unity Version - 2019.3.15f1
Adventure Creator Version - 1.69.2

Comments

  • edited February 2021

    Can you share details of an object with multiple Remember scripts that don't work, vs one that does?

    There should no longer be a need to separate such components, provided you're not using any custom Remember scripts. If you do, you'll have to edit the FileFormatHandler_Json class to make mention of them.

    An issue related to the loading of Json files was also addressed in 1.69.5.

    I would recommend you import the latest AC into a duplicate project, go through the "Upgrade notes" section of the Changelog, and then check to see if the issue remains in the latest release. Whether or not you can upgrade the actual project, we'll first need to determine if this is an issue that's since been addressed.

  • edited February 2021

    Hi Chris.

    Object A: Remember does not work.
    Details: It has 2 remember scripts. Remember Hotspot and Remember Spell(custom script). Below is the code for the remember spell script.

    {
    public override string SaveData() {
    SpellData nameData = new SpellData();
    nameData.objectID = constantID;
    nameData.savePrevented = savePrevented;

            SpellLearningTemplate spellObject = gameObject.GetComponent<SpellLearningTemplate>();
            nameData.spellComplete = spellObject.IsSpellComplete;
            nameData.spellActivated = spellObject.IsSpellActivated;
            nameData.spellDiscovered = spellObject.IsDiscovered;
            nameData.activateBasedOntimer = spellObject.ActivateBasedOnTimer;
            nameData.activateBasedOnActivityCount = spellObject.ActivateBasedOnActivityCount;
            return Serializer.SaveScriptData<SpellData>(nameData);
        }
    
        public override void LoadData(string stringData)
        {
            SpellData data = Serializer.LoadScriptData<SpellData>(stringData);
            if (data == null) return;
            SavePrevented = data.savePrevented; if (savePrevented) return;
    
            SpellLearningTemplate spellObject = gameObject.GetComponent<SpellLearningTemplate>();
            spellObject.IsSpellComplete = data.spellComplete;
            spellObject.IsSpellActivated = data.spellActivated;
            spellObject.IsDiscovered = data.spellDiscovered;
            spellObject.ActivateBasedOnTimer = data.activateBasedOntimer;
            spellObject.ActivateBasedOnActivityCount = data.activateBasedOnActivityCount;
        }
    

    }

    Object B: Remember does work.
    Details: It has 2 remember scripts. Remember Hotspot and Remember Activity Readiness(custom script). Below is the code for the remember activity Readiness script.

    {
    public override string SaveData()
    {
    ActivityReadinessData nameData = new ActivityReadinessData();
    nameData.objectID = constantID;
    nameData.savePrevented = savePrevented;

            ActivityReadiness activityReadinessObject = gameObject.GetComponent<ActivityReadiness>();
    
            nameData.activityCurrentTimer = activityReadinessObject.currentTimer;
            nameData.currentActivityState = activityReadinessObject.CurrentActivityState;
            nameData.activatebasedOfReadiness = activityReadinessObject.ActivateBasedOfReadinessOnly;
            //nameData.activateTimer = activityReadinessObject.ActivateTimer;
            return Serializer.SaveScriptData<ActivityReadinessData>(nameData);
        }
    
        public override void LoadData(string stringData)
        {
            ActivityReadinessData data = Serializer.LoadScriptData<ActivityReadinessData>(stringData);
            if (data == null) return;
            SavePrevented = data.savePrevented; if (savePrevented) return;
    
            ActivityReadiness activityReadinessObject = gameObject.GetComponent<ActivityReadiness>();
    
            activityReadinessObject.currentTimer = data.activityCurrentTimer ;
            activityReadinessObject.CurrentActivityState = data.currentActivityState;
            activityReadinessObject.ActivateBasedOfReadinessOnly = data.activatebasedOfReadiness;
            //activityReadinessObject.ActivateTimer = data.activateTimer;
        }
    

    }
    I will import AC in a duplicate project and check if the issue still exists. Will update back here. Thanks Chris..

  • edited February 2021

    A bit of a hack necessary with Json is that it can't distinguish what type of save data it is before its been deserialized.

    When multiple Remember components are attached to the same object (and so have the same ID), you either need to manually assign a new ID to each component - or update the FileFormatHandler_Json class to filter out save class mismatches. By that, I mean:

    if (jsonData is NameData && !jsonString.Contains ("newName"))
    {
        return null;
    }
    

    This little snippet ensures that a RememberName component (which saves in a NameData class) can be loaded into if the data contains the "newName" variable.

    If you're using a custom Remember class, you'll need to add additional such checks for your own classes in this script. (Though, again, you should be able to manually assign separate IDs instead).

    Also know that it's possible to make such script changes in a duplicate FileFormatHandler_Json class, and assign that as your file format handler, so as to avoid overwriting your changes when updating AC. See the Manual's "Custom save formats and handling" chapter for details on how to do this.

  • Thanks once again Chris. This works like a charm.

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.