Forum rules - please read before posting.

Game registers too many mouse clicks on inventory menu

Hi

I have made a custom inventory menu, using the AC prefab as template.
I am experiencing a strange behaviour with mouse clicks on the menu slots.
Every time I click on a slot, 3 clicks are registered.
I have made a custom script to report every mouse click and it reports 3 clicks every time I click once.
This seems to result in strange behaviour on the menu, fx. item-interaction menu flashing briefly and then disappearing when you click on an item, i.e. not staying in place so you can choose an action.

I am using multiple interactions and reorder items ON. If I use single interaction instead, I see 1 or two clicks recorded depending on if I have a standard use action registered for the clicked item.

I assume that the multiple click behaviour is not intended and that it is this that disturbs the interaction menu so it will not stick after a button-click - but I might be misunderstnding something, of course :-)

I have provided links to images of the settings menus involved:

https://imgur.com/uxf7EhU
https://imgur.com/9hf1wi6
https://imgur.com/qWEhHZ3
https://imgur.com/qp8Bk62
https://imgur.com/xlBfCQZ
https://imgur.com/tS2h4uX

Comments

  • edited November 2020

    I'll just add a little more info.
    In the image below I have shown the report that I generate in the debug log.
    This report is generated with 1 left-click and 1 right-click.
    So the first left-click registered as 3 left clicks and the right-click thereafter registered as 1 right-click and 1 left-click.
    When I left-click, the interaction menu appears in a short flash and goes away again.
    When I right-click, the interaction menu appears and stays in place as it should.

    EDIT: Forgot to supply image link:
    https://imgur.com/Td5TWm8

    For good measure, here is the script I use to generate the report:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class InventoryChecks : MonoBehaviour
    {
        private void OnEnable()
        {
            EventManager.OnMenuElementClick += ElementClick;
        }
    
    
        private void OnDisable()
        {
            EventManager.OnMenuElementClick -= ElementClick;
        }
    
    
        private void ElementClick(AC.Menu _menu, MenuElement _element, int _slot, int _buttonPressed)
        {
            if (_menu.title == "Inventory" && _element.title == "PlayerInventory")
            {
                MenuInventoryBox menuInventoryBox = (MenuInventoryBox)_element;
                if (_buttonPressed == 1)
                {
                    Debug.Log("Button 1 pressed");
    
                    if (KickStarter.runtimeInventory.LastClickedItem != null)
                    {
                        Debug.Log("LastClickedItem: " + KickStarter.runtimeInventory.LastClickedItem.label);
                    }
                    else
                    {
                        Debug.Log("LastClickedItem: None");
                    }
    
                    if (KickStarter.runtimeInventory.LastSelectedItem != null)
                    {
                        Debug.Log("LastSelectedItem: " + KickStarter.runtimeInventory.LastSelectedItem.label);
                    }
                    else
                    {
                        Debug.Log("LastSelectedItem: None");
                    }
                }
                else if (_buttonPressed == 2)
                {
                    Debug.Log("Button 2 pressed");
    
                }
            }
        }
    }
    
  • edited November 2020

    Where are you placing your custom script? Is there only one instance of it in the scene?

    One click should register once. What are your AC/Unity versions, are you relying on a custom EventSystem (either a prefab or in the scene file), and does this occur with the default Inventory menu/prefab?

  • edited November 2020

    I am placing the custom script with the "reporting" code on a gameobject in the scene called MyScripts. When I deactivate that script, no reporting is done.
    EDIT: And yes, there is only one instance in the scene.

    AC version is 1.72.3.
    Unity version is 2019.4.4f1.
    I don't use a custom EventSystem.
    Same thing happens if I use the default AC InventoryUI prefab.
    If I set the source for the menu to AC, however, only 2 clicks are registered, as compared to 3/4 clicks with a prefab.
    An interesting observation is that with source=AC, the Interaction list pops up and stays exactly as it should (though still 2 clicks are registered, as mentioned).

  • edited November 2020

    Thanks for the info.

    Is your Inventory menu paused at the time, and are you getting similar behaviour with other Menus?

    If I set the source for the menu to AC, however, only 2 clicks are registered

    You're inferring this from the custom script? Would this be a case of click-down and click-up events both invoking the event? Try clicking slowly to see if they're separated.

  • Menu was set to pause game when enabled.
    I unticked this option but behaviour is the same.

    Yes, I am inferring the number of clicks from my own script.

    You were spot-on with the down-up events!
    When clicking slowly, it becomes obvious that this has something to do with it.
    When using AC source it registers 2 clicks: 1 is registered at down and 1 at up.
    When using unity prefab, 3 clicks are registered: 1 at down and 2 afterwards at up.
    When using unity in scene, 4 clicks are registered: 1 at down, 3 at up.

    So there is a pattern here at least :-)

    AC source works as it should I guess - but the others register too many clicks at the up event.
    With both prefab and in-scene, the interaction menu fails to stick - while with AC source it sticks after clicking so you can choose an interaction.

  • More info.
    I made a completely new Inventory menu following the guide here:
    https://adventurecreator.org/tutorials/creating-inventory-bar-unity-ui
    The behaviour is completely the same with this one as when I use my own custom menu as prefab.

  • edited November 2020

    You should only be getting one event per-click - and this is the behaviour I get when listening to the event myself, so it's not an issue I can recreate.

    Could it be that you have multiple Inputs e.g. mapped to "mouse 0" in your Input Manager that are somehow triggering simultaneously?

    Let's see if there's a difference in the way the events are triggered. When using AC as the Menu's Source, click once to get two events as before. Then, check the stacktrace for the two Console messages. Are they the same, and can you share them in full?

  • Yes, will do.
    Using AC as source I get 2 messages on a left click:

    Message 1:

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2260)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1867)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1969)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1960)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:195)

    Message 2:

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2260)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1894)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1969)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1960)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:195)

    This looks like the normal behaviour to me.
    Which is confirmed by the fact that the interaction menu behaves fine in this case - it sticks and you are able to click the buttons.

    Just for good measure here are the two messages for a right click:
    (the right click gives 1 "button 1" register and 1 "button 2".

    Message 1 (registered as a button 2 click):

    Button 2 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:58)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2260)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1867)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1969)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1960)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:195)

    Message 2 (registered as a button 1 click):

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2260)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1894)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1969)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1960)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:195)

    I will try and do the same when the menu is set to prefab and in-scene.

  • Here are the 3 messages when I left click on the menu with source set to prefab:

    Message 1:

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2260)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1882)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1969)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1960)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:195)

    Message 2:

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.MenuElement:ProcessClickUI(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:260)
    AC.<>c__DisplayClass38_0:b__0() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:216)
    UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.4.4f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

    Message 3:

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1889)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1969)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1960)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:195)

  • And the 4 messages with source Unity in scene:

    Message 1:

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2260)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1882)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1969)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1960)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:195)

    Message 2:

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.MenuElement:ProcessClickUI(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:260)
    AC.<>c__DisplayClass38_0:b__0() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:216)
    UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.4.4f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

    Message 3 (exactly the same as message 2):

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.MenuElement:ProcessClickUI(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:260)
    AC.<>c__DisplayClass38_0:b__0() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:216)
    UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.4.4f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

    Message 4:

    Button 1 pressed
    UnityEngine.Debug:Log(Object)
    InventoryChecks:ElementClick(Menu, MenuElement, Int32, Int32) (at Assets/Trump/Scripts/InventoryChecks.cs:27)
    AC.EventManager:Call_OnMenuElementClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:702)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2146)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1889)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1969)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1960)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:195)

  • It looks to be related to drag-and-drop.

    I wonder if its related to this addition in v1.72.3:

    Added: Ability to drag-and-drop inventory items before opening Interaction menus if the "Minimum drag distance" is non-zero

    Does this behaviour persist if you uncheck Select item if drag before opening Interaction menu??

  • I turned this option off and it is a different behaviour but not better :-)
    I get 12 click messages now.
    The item does not get selected anymore and drag doesn't work.

  • Turning off drag and drop gives same behaviour as with AC source.
    But now I can't re-order the inventory.
    If I turn off drag and drop AND use AC source, I only get 1 click message, but item is not selected and I can't reorder the inventory.

  • I get 12 click messages now.

    Oh boy.

    There's likely more at play here than just the settings you've shared.

    Can you PM me your files so that I can experience this myself? I would need a .unitypackage of your Managers, your UI prefabs, and a sample Inventory item (graphic, ActionList) added to the inventory.

  • Hi Chris
    I will be happy to.
    But I just found out that it is very easy to recreate:

    Start up a completely new game in Unity.
    Import AC.
    Create 2 items with some actions.
    Setup inventory menu as Unity prefab, linking the default InventoryUI menu.
    Then use the setting provided in the below images and you will get the behaviour where the settings are as in the images below.

    https://imgur.com/zGkO8ZY
    https://imgur.com/O19pBOl

    This gives you a completely clean setup with the same symptoms and without any of my custom stuff.
    If you want, I can send the files anyway, of course.

  • edited November 2020

    I'll just add an image of my item settings.

    https://imgur.com/zzTL0kg
    https://imgur.com/FcLQM4k

  • Thanks, this was enough to recreate it.

    It's a bug related to the necessity of AC to manually detect UI clicks when drag-and-dropping, while the UI itself is still reacting simultaneously.

    I'll see this addressed in the next update - though I'll PM you a package to test in the meantime.

  • Great that we figured it out!
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.