Forum rules - please read before posting.

SAVE GAME PROFILES

HI AGAIN
I am using the AC profile system so the user can create new profiles. But I have come across the following problem
To put you in context.
My game starts with a main menu, you can open the profiles menu and there are buttons corresponding to each level. When clicking on a level an Action List does the following depending on which scene we choose
1. SAVE: Check
is slot empty?
If condition is met: Switch Scene: scene1
if condition is not met: Load Game, Save ID to load: 1
FINISH*

In my game there are 2 scenes, in each one there is a Hotspot that if you want to save, you can click, and the following happens:
SAVE: SAVE OR LOAD
Overwrite existing save
Save ID to overwrite:1

//IF YOU ARE IN SCENE1, ACTION LIST SAVES ON ID 1
// IF IT IS IN SCENE 2, ID 2

If I am using profile 1 in the game, let's take the example that in scene 1 a door moved from 0 to 90 degrees, it has a remember moveable component, I save the game and if I go back to the main menu and press the button again from that scene, it loads successfully, the door is where it should be due to its remember moveable component.
It is supposed that if I create a profile2 (in my main menu), when i choose scene 1 it will change to a new scene1 without modifications since each profile has its save game files
BUT if after saving the game in profile1, I return to my main menu, create a profile2, click on scene1, it changes scene but the door appears as we left it in profile1, and loads everything as we saved it in profile1 however we are in profile2.
What I've noticed is that if after saving profile1, I go back to my main menu, create profile2, exit the game completely and re-enter the game and I'm in profile2, when I switch to scene1 in the profile2, everything returns to normal from that profile, the door is at its zero point and without modifications.

https://www.canva.com/design/DAFl7Vul5VQ/CsOapenXfTAmNGFaYQmsbw/watch?utm_content=DAFl7Vul5VQ&utm_campaign=designshare&utm_medium=link&utm_source=publishsharelink

I recorded a video showing the problem

AC- version 1.77.3
Unity 2021.3.f1

Comments

  • I am ussing Addressable Unity System

  • Chris should be able to confirm this, but I think this is working as intended. Switching the active profile isn't like loading save: the profile itself doesn't contain any of the game data, except for the variables you've linked to your Options Data. If you want to reset your game data when you switch profiles, you need to do that manually.

  • It's true that Profiles are treated separately to your regular save-data - though each Profile does have its own record of save files.

    How and when exactly the game's "live" data is reset/loaded will vary by the game's design, however. I shall look into providing an easier way to do so, but currently this is possible by calling the following function:

    public void ClearLiveData ()
    {
        KickStarter.saveSystem.ClearAllData ();
        KickStarter.levelStorage.ClearAllLevelData ();
    }
    

    To run this from an ActionList, place in a C# file attached to a prefab, and have the Object: Call event Action reference this prefab and run the ClearLiveData function.

  • edited June 2023

    public class ClearData : MonoBehaviour
    {
    public void ClearLiveData ()
    {
    AC.KickStarter.saveSystem.ClearAllData ();
    AC.KickStarter.levelStorage.ClearAllLevelData ();
    }
    }

    Now everything is working perfectly, i can switch across profiles and starts scenes in the way it should be

    Thank you so much

  • Happy to help.

    After looking into it some more, here's a more complete ClearLiveData function, which will reset Inventory, menus etc as well:

    public void ClearLiveData ()
    {
        KickStarter.runtimeInventory.SetNull ();
        KickStarter.runtimeInventory.RemoveRecipes ();
    
        KickStarter.saveSystem.ClearAllData ();
        KickStarter.levelStorage.ClearAllLevelData ();
    
        KickStarter.sceneChanger.OnInitPersistentEngine ();
        KickStarter.runtimeInventory.OnInitPersistentEngine ();
    
        KickStarter.runtimeVariables.TransferFromManager ();
        KickStarter.runtimeVariables.OnInitPersistentEngine ();
        KickStarter.runtimeDocuments.OnInitPersistentEngine ();
        KickStarter.runtimeObjectives.OnInitPersistentEngine ();
    
        KickStarter.playerMenus.RecalculateAll ();
    }
    

    In the next update, I'll have this be available as an option in the Engine: End game Action.

  • Hey Chris, I've been using the script you shared above, and it appears to do what it needs to do, but I think KickStarter.runtimeInventory.SetNull (); might not be the best solution for this because it overlooks the items that have "carry on start?" checked. If the idea is to reset the game state to the beginning, then we need to clear the inventory and then add the items that are carried on start.

  • ^ Sorry, I checked the scripting guide and realised that the issue was not SetNull. My bad. But the issue I reported does still happen: the inventory is cleared and none of the items that are supposed to be carried on start are added to the inventory.

  • The default inventory should be added via this line:

    KickStarter.runtimeInventory.OnInitPersistentEngine ();
    

    I cannot recreate an issue - are you involving Player-switching?

  • edited June 2023

    I have a setup like this:

    Player 0: Talia (Player)
    Player 1: (DEFAULT) Main_menu (Player)

    The reason for this is that I have a lot of scripts on the Talia prefab that I don't want to initialise until I click "Begin" and switch away from the game's first scene (main menu). I have a player switch action to Talia on the OnStart actionlist for every scene except the main menu.

    Interestingly, even though Main_menu is the default, maybe because of the order they are in, "Carry on start?" puts the item in Talia's inventory instead. This is true whether we check "Non-default players" or not: if Talia is checked as the non-default player, or if the non-default-player option is unchecked, the item will be placed in Talia's inventory when we first launch the game.

    However, when we run the code above, then items that had "Carry on start?" checked and "Non-default players" unchecked will disappear from Talia's inventory and appear in Main_menu's inventory. The items that had Talia checked as the non-default player will simply disappear. They will be removed from Talia's inventory, but will not be placed in Main_menu's inventory.

  • I think I understand where part of the wonky behaviour is coming from (before the script above even comes into play): if you check "Non-default players" and check Talia, and then uncheck "Non-default players", the item will be placed in her inventory on start. It only won't be placed there if you check "Non-default players", uncheck Talia, and then uncheck "Non-default players" again.

    The thing is that when you create a new item, "Non-default players" is unchecked, but if you check it, you will see that the first player name on the list will be checked, even if it is not the default player! It seems that all the "non-default players" checkbox is doing here is hide/display the list, but AC is still taking the list into account to know where to place the items, on the assumption that the first item on the list is the default one. This is a bad assumption though because (1) the first player prefab isn't necessarily the default; and (2) if the dev messes with the checkboxes while "Non-default player" is checked and THEN decides to uncheck it, AC will still taken the hidden options into account.

    Then when we finally run the script above, it correctly takes the "non-default player" checkbox into account if it is unchecked, but it doesn't work correctly when it is checked and a non-default player is chosen.

  • I have a player switch action to Talia on the OnStart actionlist for every scene except the main menu.

    If your Main_menu Player only exists in a single scene, an alternative to this approach would be to disable Player-switching, and place the Main_menu Player in the Main Menu scene directly. When Player-switching is disabled, a "local" Player found in the scene file will override the default for the duration of that scene.

    This is a bad assumption

    Indeed - this is a bug and will be addressed. Thanks for the details.

    On the topic of the script itself: to be clear, what is the exact behaviour you're looking for? For all items in all inventories to be reset to their defaults? This is essentially the behaviour of the "Restart Game" function.

  • edited June 2023

    On the topic of the script itself: to be clear, what is the exact behaviour you're looking for? For all items in all inventories to be reset to their defaults? This is essentially the behaviour of the "Restart Game" function.

    This is essentially what I want, and I was previously using the Engine > End Game > Restart Game action for this purpose without any issues. But aesthetically, it looked like this:

    (1) Launch game. Camera_1 fades in, profile choice menu fades in. Player picks a profile.

    (2) Camera switches to Camera_2, panning over the scene for 3 seconds; main menu fades in, with an option to switch from or delete the current profile. When the player picks the profile option, I was fading out Camera_2 and resetting the game, which led to (1) again.

    Instead of fading out and in again, I simply wanted to fade out the main menu, pan back to Camera_1, and fade the profile menu in. But functionally, I wanted the results of the Restart Game action. I thought the script above would reset the things I needed to reset, but it didn't quite do what it needed to.

    If your Main_menu Player only exists in a single scene, an alternative to this approach would be to disable Player-switching, and place the Main_menu Player in the Main Menu scene directly. When Player-switching is disabled, a "local" Player found in the scene file will override the default for the duration of that scene.

    This seems to have done the trick in my situation though. Thanks!

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.