Forum rules - please read before posting.

How do I keep a menu visible but prevent interaction?

edited March 2021 in Technical Q&A

AC ver: 1.73.2
Unity ver: 2019.4.18f1

Hello,

I have a sitation where my options menu overlays my main menu, and when this happens I want to disable any interaction with the main menu (but still keep it visible):

It's hard to see in the GIF, but the main menu buttons still respond to the pointer when the options menu is open.

I noticed there is a 'ignore input' flag on menus which sounds like the kind of thing I want to set however I can't find an action that gives me access to that.

How do I lock out the main menu so it's still visible but can't be interacted with?

Thanks!

Comments

  • It's too specific for there to be a dedicated built-in Action for it, but any Manager field can be accessed through script. Right-click the field's label to get an API reference to it. In the case of the "Ignore input?" option, it's:

    AC.PlayerMenus.GetMenuWithName ("MyMenu").ignoreMouseClicks
    

    However, Unity UI-based menus are a little different, since they rely on Unity's Event System for interaction.

    Either as well as, or instead (you'll need to experiment), you may have to set the "Interactable" state of a Canvas Group component attached to the canvas's root. This can be automated based on the state of the Options menu through script:

    using UnityEngine;
    using AC;
    
    public class ToggleMenuInteractivity : MonoBehaviour
    {
    
        public CanvasGroup canvasGroup;
    
        private void OnEnable ()
        {
            EventManager.OnMenuTurnOn += OnMenuTurnOn;
            EventManager.OnMenuTurnOff += OnMenuTurnOff;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuTurnOn -= OnMenuTurnOn;
            EventManager.OnMenuTurnOff -= OnMenuTurnOff;
        }
    
        private void OnMenuTurnOn (AC.Menu menu, bool isInstant)
        {
            if (menu.title == "Options")
            {
                canvasGroup.interactable = false;
            }
        }
    
        private void OnMenuTurnOff (AC.Menu menu, bool isInstant)
        {
            if (menu.title == "Options")
            {
                canvasGroup.interactable = true;
            }
        }
    
    }
    
  • edited March 2021

    Thank you Sir. I'll give it a go!

  • Sorry to hijack this, and not sure if this deserves a new topic thread altogether, but is this same thing possible to do with elements of the same menu?

    IE, if you select an object in an inventory box, a group of buttons in a little menu become active, whilst the inventory box group is disabled.

    I'm not sure how to force the selection to sit inside the newly enabled "menu box" instead of remaining in the inventory box.

    I can get it working if that sub menu is it's own menu - essentially as you've shown in the above script, but to save on having a whole bunch of prefabs for what amount to parts of a whole menu screen, I figured I'd have them as elements of the same "Inventory menu" - an inventory box, and the aforementioned buttons that enable once you've selected an item (alongside labels and an image etc.)

    Except it's kicking my ass.

  • edited March 2021

    AC or Unity UI based?

    The above trick of using a Canvas Group to prevent interactivity isn't limited to an entire canvas - you can place it anywhere to disable any set of child objects in the hierarchy.

    The component's Interactable property could also be animated, and controlled via the Object: Animate Action, to avoid scripting.

    To enforce selection of a particular object - again, using Unity UI - is a case of manipulating Unity's EventSystem object. AC provides a function to handle this, however:

    AC.KickStarter.playerMenus.SelectUIElement (objectToSelect);
    
  • I’m using unity for the final version, but AC to hash it out first.
    One other quick question, is it possible to rehilight the previously selected inventory item when you back out, in the same way, or would that require further fandangling?
  • I'm afraid I don't quite follow. Are you referring to the item itself (i.e. it's "Active graphic" texture), or the highlight effect of the slot it's displayed in? When would such an effect be shown?

    Screens / mockups to illustrate would help clarify the situation.

    The highlighting of inventory items is controlled internally based on the item's selected state, but when using Unity UI you can further control the appearance of things, e.g. by changing the color transitions of the Button component, or animating other Image components in the same space.

  • Oh sorry, highlight was the wrong term.
    So with a menu that’s direct controlled, I mean like the element that is selected first, but not clicked on yet. I guess it’s analogous to hovering the mouse, but I’m not sure how to force it to a specific box in an inventory.
    Reason I want to is that in my menu, you move around items in a 3by3 inventory box grid with wasd or the controller stick, then press the interactA button on an item.
    I have an event that then triggers a submenu to open which, based on the category of the currently selected item displays buttons (use and move/combine for all items, and discard - if the item selected has the “discardable” property)
    This all works just fine, but when you select the move/combine button, I close that submenu and return to the inventory box with the previously selected item still selected.
    At this point you can move over another item and press interactA to do their combine interaction.
    What I was hoping to do is have it so that when that menu closes for moving or combining, the item that is “highlighted”/hovered over is the one originally selected to open the menu, instead it always defaults to the top left box and whichever item is in that box.
    I’ll see if I can upload a gif to show you what I mean, but hopefully that makes sense.
    I think the selected/highlighted/clicked terms between unity and AC might differ which has got me chasing my tail!
  • Here's a gif of what I've got.

    https://imgur.com/a/zwH9MwF

    The Down arrow and Red cross are placeholders of the item's selected graphic, whereas the little highlighter outline thing is an image that sits over each inventory button in unity, and i've linked the "highlighted sprite" in each inventory box button to the respective blank image that sits over the top.

  • edited March 2021

    Thanks for the clarification.

    To select a specific element slot, you can use the Menu.Select function, or the Menu: Select Action. Typical usage of the function would be something like:

    AC.PlayerMenus.GetMenuWithName ("MyMenu").Select ("MyElement", 3);
    

    Where "3" is the index of the slot you wish to select, inside that element.

    As a test, try simply using the Action to force-select a specific slot while the Menu is navigable.

    Assuming all's working, what you'll then need to do is work out which slot needs selecting - which is a case of taking the inventory item that was last interacted with, and getting it's associated slot number in the Inventory menu.

    In your event that triggers the sub-menu, do you have a reference to the item's InvInstance? If so, you can use the InventoryBox element's GetItemSlot function to get the slot index:

    int slotIndex = (PlayerMenus.GetElementWithName ("MyMenu", "MyElement") as MenuInventoryBox).GetItemSlot (invInstance);
    

    It would then be a case of recording this value, and passing it to the Select function once the sub-menu is closed (assuming you're controlling that turning off through script as well).

  • Oh radical! That’s exactly what I needed! Thank you so much Chris, yet again it’s astounding just how much functionality you’ve wrapped up in AC.
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.