Forum rules - please read before posting.

Open inventory menu with hover/mouse over a "UI Element" (other menu)

edited July 2021 in Technical Q&A

Hi,

I have a menu with Apear type set to During Gameplay (OpenInventoryMenu). The menu contains a single button at the bottom of the screen. Clicking on that button opens the actual inventory menu. But now I don't want to open the inventory menu by clicking the "OpenInventoryMenu" menu but with mouse over, and close it when hovering out of the inventory menu.

I dont't want to use the Appear type: mouse over because the area of the inventory menu is too big.

Ultimately the player should go with the mouse to the border of the screen (very thin button maybe?) to open the inventory menu.

Maybe there is a better approach to do this.

Thanks for any answer!

Raul

Comments

  • edited July 2021

    If a Menu is locked, it will remain turned off even if its "Appear type" condition is met. You can keep the Inventory menu set to appear during gameplay, locked by default (the Start game locked off? property), and then unlock it when they mouse over OpenInventoryMenu.

    You can have a custom script hook into the OnMouseOverMenu custom event to detect when the player has begun hovering over a particular menu, but you also need to detect when the player has left the Inventory menu in order to close it. Something like this should do it:

    using UnityEngine;
    using AC;
    
    public class CustomInventoryMenu : MonoBehaviour
    {
    
        private Menu inventoryMenu;
        private bool isOverInventory;
    
        private void OnEnable () { EventManager.OnMouseOverMenu += OnMouseOverMenu; }
        private void OnDisable () { EventManager.OnMouseOverMenu -= OnMouseOverMenu; }
    
        private void OnMouseOverMenu (AC.Menu _menu, MenuElement _element, int _slot)
        {
            if (_menu.title == "OpenInventoryMenu")
            {
                isOverInventory = false;
                inventoryMenu.isLocked = false;
            }
            else if (_menu.title == "Inventory")
            {
                isOverInventory = true;
            }
        }
    
        private void Update ()
        {
            if (inventoryMenu == null) inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory");
    
            if (isOverInventory && !inventoryMenu.IsPointInside (KickStarter.playerInput.GetInvertedMouse ()))
            {
                isOverInventory = false;
                inventoryMenu.isLocked = true;
                inventoryMenu.TurnOff ();
            }
        }
    
    }
    
  • Yeah that work pretty good! thx

    But ;) the inventory menu does not close when leaving the menu

  • I've updated the above - give it another try.

  • edited December 2024

    Hi Chris, I have 2 Inventory boxe elements(1 for each category) in my inventory menu and I am trying to hide/unhide these elements depending on which scene the player is in. When using this script you provided above, whenever there's an Inventory element(InventoryBox) hidden from the beginning, it gives me this error. How can I fix this? Thanks in advance.

    "Couldn't find menu with the name 'Inventory'

    -> AC debug logger
    UnityEngine.Debug:LogWarning (object,UnityEngine.Object)
    AC.ACDebug:LogWarning (object,UnityEngine.Object) (at Assets/AdventureCreator/Scripts/Static/ACDebug.cs:39)
    AC.PlayerMenus:GetMenuWithName (string) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2822)
    CustomInventoryMenu:Update () (at Assets/PointClick/Scripts/OpenInventoryMenu.cs:28)"

  • whenever there's an Inventory element(InventoryBox) hidden from the beginning, it gives me this error.

    Sorry, to be clear: does this mean it works when your element is visible by default?

    Is your Inventory menu named "Inventory", and what's your AC version?

    The message you've pasted should only be a Warning - are you getting an Error message as well? Try replacing:

        if (isOverInventory && !inventoryMenu.IsPointInside (KickStarter.playerInput.GetInvertedMouse ()))
    

    with:

        if (inventoryMenu != null && isOverInventory && !inventoryMenu.IsPointInside (KickStarter.playerInput.GetInvertedMouse ()))
    
  • edited December 2024

    whenever there's an Inventory element(InventoryBox) hidden from the beginning, it gives me this error.

    Sorry, to be clear: does this mean it works when your element is visible by default?

    The game runs, but the Inventory menu doesn't work. The item graphic in the Inventory menu doesn't show up even though I can see the lable when hovering over the item.

    Is your Inventory menu named "Inventory", and what's your AC version?

    Yes is named "Inventory". The AC version is v1.81.7

    The message you've pasted should only be a Warning - are you getting an Error message as well? Try replacing:
    if (isOverInventory && !inventoryMenu.IsPointInside (KickStarter.playerInput.GetInvertedMouse ()))
    with:

    if (inventoryMenu != null && isOverInventory && !inventoryMenu.IsPointInside (KickStarter.playerInput.GetInvertedMouse ()))

    Not getting an error, the message keeps coming up on the console, and can't move the character nor bringing up the menu...etc. Replaced this code, still the same.

    Does having 2 Inventory boxes and switching them back and forth in 1 menu create any conflict?
    I am using the show/hide menu element action, and from what I am seeing, only the Inventory Box element that's in the front is displaying properly, the one behind either shows up without graphics "when slot is empty: clear content", or nothing showing at all "when slot is empty: Disable Object", even though the Inventory Box element in front is hidden.

  • The item graphic in the Inventory menu doesn't show up even though I can see the lable when hovering over the ite

    So the Inventory element is invisible, but the Hotspot menu is behaving as though it is?

    Not getting an error, the message keeps coming up on the console, and can't move the character nor bringing up the menu...etc. Replaced this code, still the same.

    The warning relates to the naming convention of your menu - is your Menu named "Inventory"? If not, adjust the code so that it references the different name.

    Does having 2 Inventory boxes and switching them back and forth in 1 menu create any conflict?
    I am using the show/hide menu element action, and from what I am seeing, only the Inventory Box element that's in the front is displaying properly, the one behind either shows up without graphics "when slot is empty: clear content", or nothing showing at all "when slot is empty: Disable Object", even though the Inventory Box element in front is hidden.

    If your Menu uses Unity UI, there could be a conflict if the "hidden" top Inventory is still clickable, which'll be the case with the "Clear Content" setting.

    Can you elaborate on the underlying situation, and the need to rely on 2 separate InventoryBox elements? If it's to e.g. display items in different categories, it may be easier to use custom code to change categories shown in a single element.

  • I wanted to have a set of inventory for the real world, and another for the dream world. After changing the Inventory menu to using AC from unity UI, everything seems to work perfectly now.
    This warning is most likely caused by the scene itself because I tried it in another scene and it seemed to work. I should have tried it first but thought it was only menu related.
    Everything seems to work out now, thank you so much for your time Chris. You are the best.

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.