Forum rules - please read before posting.

Keeping inventory open when examining items

Hi there
The game I'm working on has an inventory that slides in from the top of the screen when the cursor is moved up (using the "Mouse Over" setting in Appear type
When I examine an item using right click the cutscene plays and the inventory menu closes

I found this thread about the same issue
https://adventurecreator.org/forum/discussion/8153/inventory-stay-after-open-after-examining-inventory-item

From this thread I gather the behavior is expected because the menu automatically gets turned off when gameplay is paused
I could set it to manual but then I wouldn't really know how to handle the opening and closing when the mouse leaves the inventory

Is there a way to keep the mouse over behavior but let the menu stay active while the game is paused?

Comments

  • OK I figured it out!
    If anyone wants to have the same behavior here's how you do it

    First, you want to set your Inventory Menu's Appear type to "Manual"

    Then you want to create a new UI Element (I call it Inventory Activator) and set its appear type to "During Gameplay" so that it only shows up during gameplay, this menu should on top of your screen or wherever you want the cursor to be in to keep the inventory open and it should consist in just an Image that you can make disable when you're done testing so it doesn't actually appear

    Then you'll want to create two actionlists, one to show the Inventory and one to Hide it, these are simple one action action lists that use Menu > Change State > Turn On/Off Menu

    Finally, create this script and attach it somewhere in your Inventory Activator

    using AC;
    using UnityEngine;
    using UnityEngine.InputSystem;
    
    public class ActivateInventory : MonoBehaviour
    {
        [SerializeField] private RectTransform triggerArea;
        [SerializeField] protected ActionListAsset showInventoryActionList = null;
        [SerializeField] protected ActionListAsset hideInventoryActionList = null;
    
        private bool isInside;
    
        void Update()
        {
            if (Mouse.current == null)
                return;
    
            Vector2 mousePosition = Mouse.current.position.ReadValue();
    
            bool nowInside = RectTransformUtility.RectangleContainsScreenPoint(triggerArea,mousePosition,null);
    
            if (nowInside && !isInside)
            {
                isInside = true;
                Debug.Log("Showing");
                showInventoryActionList.Interact();
                // KickStarter.menuManager.GetMenuWithName("Inventory").TurnOn();
            }
            else if (!nowInside && isInside)
            {
                isInside = false;
                Debug.Log("Hiding");
                hideInventoryActionList.Interact();
                // KickStarter.menuManager.GetMenuWithName("Inventory").TurnOff();
            }
        }
    }
    

    You'll need to assign triggerArea to your activation zone boundary and the two action lists you created to other two properties

    If done correctly the inventory menu should show when you move your cursor into the top of the screen and dismiss when you leave the area, make sure the area you created is tall enough to hold your inventory screen

    I initially tried to call TurnOn and TurnOff on the menus using the menuManager but it had a lot of problems I couldn't solve, using the actionlists works perfectly

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.