Forum rules - please read before posting.

Not closing a menu

Hello guys!
I'm going bananas on this but I can't find a way to just not disable the gameobject which is the inventory on certain moments, such as pause or dialogues. The inventory must be present at every moment and can't find a way to just not let it turn it off. And when I do, there's this one or two frames in which it blinks and doesn't look right.

Any way to achieve this particularly for the inventory menu? I'm using Mouse over and during gameplay. Unfortunately every time it has "to go", it goes and can't find a way to stop it. I want to actually have control over it but locking it when I want.

v1.74.5
Unity 2020.3.27f1
Thanks a lot

Comments

  • The Menu "Appear type" setting of "Mouse Over" only applies during gameplay and (optionally) pause mode.

    To have a Menu display at all times, set this instead to "Manual", and use a script to turn it on/off manually based on the cursor position:

    using UnityEngine;
    using AC;
    
    public class PersistentInventoryMenu : MonoBehaviour
    {
    
        Menu inventoryMenu;
    
        void OnEnable () { EventManager.OnInitialiseScene += OnInitScene; }
        void OnDisable () { EventManager.OnInitialiseScene -= OnInitScene; }
    
        void OnInitScene ()
        {
            inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory");
            inventoryMenu.LoadUnityUI ();
        }
    
        void Update ()
        {
            if (inventoryMenu.IsPointInside (KickStarter.playerInput.GetInvertedMouse ()))
            {
                inventoryMenu.TurnOn ();
            }
            else
            {
                inventoryMenu.TurnOff ();
            }
        }
    
    }
    
  • Hello Chris,

    Thanks for the script. It works, but unfotunately I can't hover or click on anything. I have a Canvas, inside I have a Panel which is the whole screen (alpha in zero). The idea is that you can always see the inventory down there, and when you hover down, it liftes. On mouse over, it just "kills" the object. If I can see it constantly, I'm good to go (except when I really want it away).

    I tired canvas group, resorting the menus, everything, for hours. The only thing I found is that when you disable the canvas, then press plan, and then enable it, it works. There is something at the beginning that just steps on top of everything else. Is there any way to "cheat" it?
    Thanks a lot. Screenshots below.

    https://imgur.com/a/kKPmww7

  • edited April 2022

    AC looks to the "RectTransform boundary" when determining if the mouse is over it - so if the Panel spans the screen, then this will always be the case. You should limit the Panel's size to just the area you want it to cover.

    I'm not fully understanding what you're looking to achieve. Does the Inventory cover the whole screen when it's "on"? In that case, when would the menu close?

    If the mouse going to the bottom of the screen should only turn the menu on - and not turn it off when leaving this area - you could rely on a "dummy" menu that spans this area, is invisible, and turns on the visible Inventory menu by assigning an "ActionList when turn on" asset that has a "Menu: Change state" Action.

    I'd also advise against using "In Scene" menus unless you have a special need to.

    As this is a visual issue, though, best to share images of what exactly you're going for.

  • Hello Chris,
    Thanks for the reply.
    I will explain what my problem is right now and from there you will probably understand it better.

    I have the inventory (yes, you said it's better to use prefabs but currently the scripts are checking things "on screen" as I'm prototyping ATM), and that inventory is on mouse over: when you hover over the lower part, it triggers an animation (from the animator) which brings the wallet/inventory to the middle of the screen The Inventory is supposed to be always visible but will only rise when you hover over the lower part of the screen. That's why I have the visible inventory (which is just a mockup/prop down there called "idle") and the real inventory which triggers when you enter or hover the panel down there. Reason why? Because the panel disables when it's off-screen.

    Now... the inventory has a second inventory which is the yellow pen you see on the right (when you click, it opens a notebook). That pen lifts as well, either when it's down there on the wallet as "idle" or when you raise the whole wallet, when you hover over it.

    The main problem: the glitch I'm having is that the pen is part of the wallet and when it rises, it takes the position of the (let's say) recorded transform position, so sometimes when you are hovering you can see that the pen is rising and then if you go down a bit, the "real" wallet (and pen) appears and creates this unwanted effect in which both pens overlaps. There's a picture in which you can see it.

    From that point I started asking questions on how I could always see the inventory and get rid of the second "idle" mockup inventory I have down there, which is just a picture, that stays there forever until you hover over and the real one overlaps and rises.

    I went further and took the pen out of the whole wallet so I could make it behave by itself but then I found that the option "on mouse over" can affect the velocity of the animation if you move the mouse faster (then again, if there's a way to have a constant speed, I could cheat my way around but it seems it takes the velocity of the mouse to increase the velocity if you forcefully move it away from the panel).

    Since they are all UI Images I tried to hide or show them after the animation completes from Action Lists but Object-Visibility doesn't work for Images (or at least I can't make it work), so I've added a script which executes inside the animation when it's done (except when it turns it off like in the Pause Menu in which the animation doesn't complete.... I created a special custom script for that case).

    Going back to where we are (and the pictures I sent before): I created a panel, the grey panel you see (which expands through the whole screen so that the script works and knows that the mouse is over the screen) and on the red part, that's where the wallet should be (again, it's a prototype made of blocks), but the problem I had is that it didn't detect any single interaction or click inside the screen That way, if the inventory is always present, I could get rid of the animations and get rid of the mockup inventory (the prop) behind. But it didn't detect a any interaction or option inside menus.

    The main issue here for us is that the Panel is disabled when it's off. I want it to detect it's off but not make it disabled, unless I really want to kill it (which I can do it by a script or trigger an animation and kill it from there). That's the main thing or problem. Have it present, when you hover trigger an animation, and when you are off the screen, trigger another but not close it, just leave it there where the animation stops.

    I'm not sure it's possible to do: the inventory panel disappears when you are off the screen, hence, everything you added inside is gone, and if I add a second inventory, it will behave the same way disabling it when you close it. If there's a way to have it present there except when you close it via Action List-Turn Off or via a script, then I'm good: I won't be needing a second prop inventory behind.

    Sorry for the long message but I promise that if I find a way to make this work I will post here either the script or config in case anyone wonders the same thing.

    https://imgur.com/a/cqK52fi

    Let me know if any of this can also help you or the community in any way.
    Thanks a lot.

  • Thanks for the explanation.

    Having a "dummy" menu at the bottom that serves as a means to reveal the "real" menu when hovering over it is a valid approach. This doesn't necessarily need to be visual, however: an empty RectTransform that spans the intended area - with no Images to represent it - is enough.

    It's true that when a Menu is turned off, it's GameObject is disabled completely. I'd suggest having the Inventory menu remain on at all times - but using animation to move it up and down, based on the mouse position.

    This could be done through script, or - as I mentioned above - using the dummy menu's "ActionList when turn on" asset to show it. If your Menu has an Animator attached to its Panel that has "pan up" and "pan down" animations, you can control playback using the "Object: Animate" Action.

    If this technique gives you an interactability issue - with this or other menus - that'll be something to solve next, but I'll need more details.

  • Hello Chris,
    I've got so many more ideas to try before writing you all again, that I will need to test things out before sending you more messages. I'll keep you all posted and see what we can do to improve this perfomance. Maybe there's a simpler solution!
    Thanks for everything and for the time you took to read the messages.

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.