Forum rules - please read before posting.

Suggestion: Specify which menus are persisted during save

Hi there,

Some menus are contextual in nature, and it's great that it's included in the save game whether they are shown or not. But some menus are global in nature and once I turn them off I don't want them to be shown again after loading a saved game.

It would be great if it could be set on a per menu basis which ones state are persisted during saves. Having to keep track of which are open and not running that logic each time a game is loaded is a bit of a hassle.

Thanks

Comments

  • Can you share details on a typical scenario where this would be useful?

  • Here's a couple of example of menus I don't want to be saved:

    • A feedback button used to report bugs
    • An FPS counter
    • A Console window used by testers

    But it might well also be something more common such an inventory menu or crafting menu that covers most of the gameplay. Even if it happens to be open during save, it may feel more natural not to have it open after loading the game.

    It just provides a more flexibility, leaving the choice to the game dev. By default, every menu could be saved so it works exactly as today.

    Oh, and this might also be the most natural way of not saving the Save (or Pause) menu when pressing the save button.

  • Try this script - it hooks into the OnBeforeLoading / OnFinishLoading custom events to back up and restore menu "on" states at the point of loading:

    using UnityEngine;
    using AC;
    
    public class PersistMenus : MonoBehaviour
    {
    
        [SerializeField] private string[] menuNames = new string[0];
        private bool[] menusAreOn;
    
        private void OnEnable ()
        {
            EventManager.OnBeforeLoading += OnBeforeLoading;
            EventManager.OnFinishLoading += OnFinishLoading;
        }
    
        private void OnDisable ()
        {
            EventManager.OnBeforeLoading -= OnBeforeLoading;
            EventManager.OnFinishLoading -= OnFinishLoading;
        }
    
        private void OnBeforeLoading (SaveFile saveFile)
        {
            menusAreOn = new bool[menuNames.Length];
            for (int i = 0; i < menusAreOn.Length; i++)
            {
                Menu menu = PlayerMenus.GetMenuWithName (menuNames[i]);
                menusAreOn = menu != null && menu.IsOn ();
            }
        }
    
        private void OnFinishLoading ()
        {
            for (int i = 0; i < menusAreOn.Length; i++)
            {
                Menu menu = PlayerMenus.GetMenuWithName (menuNames[i]);
                if (menu != null)
                {
                    if (menusAreOn[i]) menu.TurnOn (false);
                    else menu.TurnOff (false);
                }
            }
        }
    
    }
    
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.