Forum rules - please read before posting.

Save File Compatibility Issue

Previous version of my game:
Unity 2018.2.9f1 (64-bit) and AC 1.65.0

Current version of my game:
Unity 2019.2.6f1 (64-bit) and AC 1.69.3

I'm working on pushing a big update to my game and I'm getting some compatibility issues with loading saves from the previous version. The previous version being almost a year old, so a lot has been added to the project (new menus, new variables, art, scenes, sounds, etc) but the saving system has remained the same. I use one save file, the auto save. The saving/loading itself works fine in the game. The problem only arises when I try to load a save file from the previous version in the current version:

It seems to be loading most of the saved data properly (variables, current player, current scene) but it's placing the player at a random(?) position in the scene (outside of the set area, where you can't interact with anything) and is creating a new camera under the MainCamera, called BorderCamera. The BorderCamera is by the player on start. No warnings or errors in console.

I suspect that this camera issue is the main cause of the load problem. I didn't create any camera by this name, nor do I add cameras to the MainCamera. So I have no idea how this is happening or where that's coming from. Any ideas or suggestions would be much appreciated.

Comments

  • edited November 2019

    BorderCamera is likely a red-herring. AC creates one automatically if you're enforcing an aspect ratio in the Settings Manager, but it won't interfere with the loading of e.g. your player's position.

    Care must be taken when loading saves made such a long time in development ago. If Variables have been added or removed since, then that data may not get properly restored.

    In the specific case of the player not appearing in the correct spot, though, no specific cause springs to mind. Are you relying on multiple player-switching, or local player prefabs?

    If an acceptable compromise, you could try to brute-force the player's position to some place safely inside the scene via your OnLoad cutscene. If that works OK, you could even look into doing this via the OnFinishLoading custom event, upon checking if a particular variable's data is present within the save file.

  • So that's where that camera is coming from. I do force the aspect ratio to 1.777778. I've never had an issue with that before.

    I use player switching, though I do that on scene switches. And the .save files I'm testing aren't specifically in an area where a player switch happens.

    I thought about snapping the player position and changing the camera back, but I'm not sure how I would do that without having to manually edit each scene in order to switch back to the proper camera and create new markers for the player to snap to (since in some cases, snapping them to PlayerStart could block progression). Which would require going through almost 200 scenes.

  • Another observation: the position of the NPCs in scene are also being shifted.

    I'm currently trying to get more .save files from users, to test it more.

  • I'm not clear on what issue you're having with the camera. What visually is going wrong with the camera itself when loading?

    A correction of the player position upon loading could be done through a custom script - no need to change each scene. For example, the following should snap the player to the scene's default PlayerStart:

    using UnityEngine;
    using AC;
    
    public class SnapPlayerOnLoad : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnFinishLoading += OnFinishLoading;
        }
    
        private void OnDisable ()
        {
            EventManager.OnFinishLoading -= OnFinishLoading;
        }
    
        private void OnFinishLoading ()
        {
            PlayerStart defaultPlayerStart = KickStarter.sceneSettings.defaultPlayerStart;
            if (defaultPlayerStart)
                KickStarter.player.Teleport (defaultPlayerStart.transform.position);
        }
    
    }
    

    You could attach that to e.g. your PersistentEngine prefab to have it work across all scenes.

    As for NPCs, we'll need to know more about the specifics of what's going on. They won't be re-positioned randomly - there'll be some pattern/reason to it. As with the player, no particular reason for this springs to mind. At the moment, all I can really do is check the compatibility between saves made with these to AC versions.

  • What I was mentioning in the previous post is that I wouldn't always want to snap the player to the PlayerStart because doing that could cause issues in certain cases, such as blocking progress of the game.

    I was assuming the camera issue was the BorderCamera thing but it may be something else? The main camera is using incorrect positions. It seems to always be by the player (outside the level) but doesn't follow player.

    I've also now seen a couple instances where it's not loading the correct player character. Could it be loading the player, player position and camera from the wrong scene? Or loading the wrong scene with the correct player/position/camera from the correct scene?

    The NPCs might be okay. The one example I had was an NPC set to follow the player, so that might have just gotten moved with the player. But I now have two instances where the NPCs are in the correct position, so I'm assuming that the NPC position is not an issue.

    I haven't been able to get too many more save files to test but I'm going to ask around a bit more and see if I can weed out any more patterns.

  • SOLVED!

    After examining the position of the player and camera on load and comparing it to the previous and proceeding scenes, I was certain of what was happening:

    It was loading the previous scene instead of the current scene but keeping the player, player position and camera position (breaking the MainCamera) of the current scene.

    So then I thought, I bet AC is using scene numbers to load scenes. I had a "loading scene" I made very early in development, I kept it in the project but had it turned off from the build settings. I recently turned it back on to test something. This changed the numbers of the scenes after it in the Scenes In Build list. So once I turned that loading scene back off, the old saves now work fine.

    Thanks for helping me figure this out!

  • Great. Indeed, save files rely on build index numbers for scene-tracking. If they get modified in between saves, this kind of issue can occur.

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.