Forum rules - please read before posting.

Temporary hide Inventory Item Icon cursor

Hi, I have a rectangular style Inventory Menu with the Appear Type set to Manual. I’ve set up my Inventory and Inventory Cursor settings as shown in this link (https://imgur.com/a/hxbYwZg). I’m trying to figure out how to hide the Inventory Item Icon next to the cursor sometimes, even when the When inventory selected option is set to Change Cursor.

In my menu, there’s a "Use" button. When I click it, the inventory window closes.

My question is:
Even though I’ve enabled the Change cursor when over? option for the "Use button", the inventory item icon still appears next to the cursor (as shown here https://imgur.com/xQg878B). I need the When inventory selected: Change Cursor feature, but I want to temporarily disable it when my mouse is over the "Use button" in the inventory window.

How can I achieve this? Thank you so much in advance.

Comments

  • Through scripting, you can read the value of MouseOverMenuElement and compare it with your Button, and alter the When Inventory selected field accordingly.

    Try this, replacing the "Inventory" and "ExitButton" strings with the name of your Inventory menu, and Exit button, respectively:

    using UnityEngine;
    using AC;
    
    public class AutoHideInventoryIcon : MonoBehaviour
    {
    
        void Update ()
        {
            MenuElement button = KickStarter.playerMenus.GetMenuWithElement ("Inventory", "ExitButton");
            bool hideInventoryIcon = (KickStarter.playerMenus.MouseOverMenuElement == button);
            KickStarter.cursorManager.inventoryHandling = hideInventoryIcon ? InventoryHandling.DoNothing : InventoryHandling.ChangeCursor;
        }
    
    }
    
  • Hi, thank you for your quick response!

    I tried the script, but I got the error: "CS1501: No overload for method 'GetMenuWithElement' takes 2 arguments" in the console. So, I tried this but

    using UnityEngine;
    using AC;
    
    public class AutoHideInventoryIcon : MonoBehaviour
    {
        void Update()
        {
            // Get the Menu by its name
            AC.Menu menu = PlayerMenus.GetMenuWithName("a_Inventory");
    
            // Get the specific MenuElement (btnUse) within the Menu
            MenuElement button = menu.GetElementWithName("btnUse");
    
            // Check if the mouse is over the button
            bool hideInventoryIcon = (KickStarter.playerMenus.MouseOverMenuElement == button);
    
            // Adjust the cursor handling based on whether the button is being hovered over
            KickStarter.cursorManager.inventoryHandling = hideInventoryIcon ? InventoryHandling.DoNothing : InventoryHandling.ChangeCursor;
        }
    }
    

    now the problem is that once the inventory window closes, the inventory icon next to the cursor doesn't reappear, even though an item is still selected. The "Use button"'s Click Type is currently set to Turn Off menu, and "Left-click deselects active item?" is unchecked.

    Could you guide me on how to fix this?

  • I can't recreate such behaviour.

    • What is your AC version?
    • What is the Menu's Source set to?
    • Is the Cursor Manager field set back to "Change Cursor" once the menu turns off?
    • Are you certain the Inventory item is still selected (clicking a Hotspot runs its Inventory interaction)?
  • edited September 2024

    Hi Chris, Thanks again for your help. And sorry for not sharing some basic information earlier.

    Adventure Creator: v1.81.6

    Unity: 2022.3.31f

    Menu Source: Unity UI Prefab

    Is the Cursor Manager set back to "Change Cursor" when the menu turns off?


    No, it stays as "Do Nothing." (https://drive.google.com/file/d/1IFozTSA4K_OY23F8qjVX7QHJZ8XfJuX3/view?usp=sharing)

    Is the inventory item still selected when clicking a Hotspot runs its Inventory interaction?


    Yes, the interaction works when I click a Hotspot.

    By the way, I followed this post (https://adventurecreator.org/forum/discussion/14782/show-use-icon-and-the-item-icon-in-the-cursor-at-the-same-time-if-hovering-over-a-hotspot) to display an extra icon when hovering over a Hotspot with an inventory item selected. In the video, the green circle behind my main cursor (the cat's paw) is the extra icon.

    I also tried creating a fresh project, but the issue persists.

  • Does the issue remain if you (temporarily) switch back to AC as the Menu's Source?

    Try replacing:

    bool hideInventoryIcon = (KickStarter.playerMenus.MouseOverMenuElement == button);
    

    with:

    bool hideInventoryIcon = KickStarter.playerMenus.MouseOverMenuElement == button && menu.IsOn ();
    
  • Thank you so much for your help! Everything is working perfectly now. The issue was that I had attached the script to the Canvas UI Prefab as a component. I tried the new script with Adventure Creator, and it worked because I attached the script to an empty GameObject in the Hierarchy instead.

    I do have a follow-up question, though: what would be the best way to trigger this script in each scene without having to create an empty GameObject with the script for every scene? Should I use the Event Editor's Scene: Begin Game and then use the Object: Call event action to trigger the script? Since this is a new topic, I'll create a separate post for it. Thanks again for all your help!

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.