Forum rules - please read before posting.

Menu Auto Turn-Off On Scene Change

I am using Menu pop-ups to display a short tutorial over a period of time, usually at the beginning of a game or level. I am also using them for other things like location hints when you enter an area and objective pop-ups. I'm not sure if this is the best way to accomplish this, but I found it quite easy to do with the action list asset and fading.

However, the player can restart the game at any point and I would have to hardcode a menu turn off during the restart action-list to make sure nothing remains when the scene is re-loaded and was wondering if there is a way to accomplish an auto-turn off for these menus instead? I have about 15 menus which will have to be hardcoded to turn off including the pause menu, any ideas?

Comments

  • edited November 2019

    Welcome to the community, @GAaron.

    If the Engine: End game Action is used with the Restart Game command, you can use the Reset Menus too? option to revert all Menus back to their default states. Have you got this option checked?

    It's also possible to hook into the OnAfterChangeScene custom event to turn off a Menu via script:

    using UnityEngine;
    using AC;
    
    public class OnSceneChange : MonoBehaviour
    {
    
        public string tutorialMenuName = "MyTutorialMenu";
    
        private void OnEnable ()
        {
            EventManager.OnAfterChangeScene += OnAfterChangeScene;
        }
    
        private void OnDisable ()
        {
            EventManager.OnAfterChangeScene -= OnAfterChangeScene;
        }
    
        private void OnAfterChangeScene (LoadingGame loadingGame)
        {
            Menu tutorialMenu = PlayerMenus.GetMenuWithName (tutorialMenuName);
            if (tutorialMenu) tutorialMenu.TurnOff ();
        }
    
    }
    
  • edited November 2019

    Thanks Chris, I'm actually using the Reset Scene command, is there no automation using this method?

    (edit)
    PlayerMenus.GetMenus() might do it actually..

    (edit 2)
    Here is my solution, it just iterates through all the menus and turns them off without requiring a persistent object (Currently what I need) but if I needed to target specific ones I'd group them by title and just check if the title contains "tutorial" or whatever before turning them off:

    private void OnEnable ()
    {
        EventManager.OnBeforeChangeScene += OnBeforeChangeScene;
    }
    
    private void OnDisable ()
    {
        EventManager.OnBeforeChangeScene -= OnBeforeChangeScene;
    }
    
    private void OnBeforeChangeScene()
    {
        List<Menu> menus = PlayerMenus.GetMenus();
        foreach (Menu menu in menus)
        {
            menu.TurnOff();
        }
    }
    
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.