Forum rules - please read before posting.

Buttons losing focus on UI menu

Hi,

When a cutscene finishes in the background, if any of my UI menus are up, they lose focus and I get stuck. Has anyone had this happen and if so, what was the fix? I don't want to trawl through the whole game changing all the cutscenes to other things.

Cheers,
Jen

Comments

  • What are your AC and Unity versions, and can you share steps to recreate such an issue? I'm not sure exactly what focus you want there to be - screenshots will help clarify.

    Are you using a mouse cursor, a simulated cursor, or directly navigating menus? Viewing the EventSystem's Inspector can reveal more about what exactly is focused.

    You can use the Menu: Select Action to force an element's selection. If necessary, this could be run automatically via events - but try running that manually once this issue occurs to see if that can be used to resolve it.

  • Unity version - 2018.4.9f1 Switch
    AC version - 1.69.3

    We are using directly navigating menus. I have made sure that I am entirely controlling the navigation, so I know the UI isn't focusing on a hidden element accidentally.

    https://drive.google.com/open?id=15Jq4k-wy3DsGZE0xIXq7EVHTaMMPX0BA

    The screen shot above shows the menu with its button highlighted/focused on/selected (whatever terminology you want to use) and unhighlighted (menu has lost all focus). We are opening these menus via action lists by calling Menu -> Turn On Menu and then we are focusing the menu onto whatever button we want with Menu -> Select element.

    When a cutscene is triggered (eg an NPC arrives at the end of a path) while a UI menu is up, the UI menu goes from the first picture to the second, ie the button becomes unselected. This leaves the player stuck as they cannot do anything on the UI screen, including exiting it and going back to gameplay.

    I do not want to have to go through the whole game and make sure no cutscenes are happening in the background. Is there a different solution?

  • edited February 2020

    I could add something to the end of every cutscene that checks for the current UI menu and re selects an element, but this would be a very unstable patch to the problem. Also, there are often a few UI menus open at once, so it would be tricky to know which element of which menu to focus on. I would rather find out why the UI is becoming unfocused when a cut scene is triggered and stop it from happening in the first place.

  • @Jen42 I had the same issue with my direct navigated menus as well. Check out the top answer in this thread:
    https://answers.unity.com/questions/943854/ui-46-disable-mouse-from-stealing-focus.html
    Worked perfect for me.

  • edited February 2020

    Direct-control over menus during Cutscenes is disabled by default, since Menus themselves are not interactive during Cutscenes.

    This is handled by the default EventSystem in the form of the OptionalMouseInputModule component. You can replace this with your own EventSystem prefab in the Menu Manager.

    The specific function in the above component that limits direct-control during Cutscenes is CanDirectlyControlMenus, which is virtual to aid subclassing. You could create a subclass of this component that overrides this function, attach it to your own EventSystem prefab, and try that.

    However, there is still the issue of Menus not being interactable during Cutscenes. An alternative you may want to consider is to have a script that re-selects whatever was last active before the Cutscene, once the Cutscene ends.

    This is a case of hooking into the OnEnterGameState / OnExitGameState custom events. Try this:

    using UnityEngine;
    using AC;
    
    public class ReselectMenuElement : MonoBehaviour
    {
    
        GameObject oldSelectedObject;
    
        private void OnEnable ()
        {
            EventManager.OnEnterGameState += EnterGameState;
            EventManager.OnExitGameState += ExitGameState;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnEnterGameState -= EnterGameState;
            EventManager.OnExitGameState -= ExitGameState;
        }
    
    
        private void EnterGameState (GameState _gameState)
        {
            if (_gameState == GameState.Cutscene)
            {
                oldSelectedObject = KickStarter.playerMenus.EventSystem.currentSelectedGameObject;
            }
        }
    
    
        private void ExitGameState (GameState _gameState)
        {
            if (_gameState == GameState.Cutscene)
            {
                KickStarter.playerMenus.SelectUIElement (oldSelectedObject);
            }
        }
    
    }
    
  • Amazing thank you both!!! I didn't expect you to give me the code, so thanks, that's saved me so much time. I had to check oldSelectedObject wasn't null in ExitGameState so it didn't undo the selecting of the UI element in the action list, but it now is working fine.

  • FYI, the UI focus problems reared their head again when I built to switch, but then look like they have gone away again after we updated AC to the newest version. So whatever you did, thank you.

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.