Forum rules - please read before posting.

"Trigger interaction by releasing click?" and Unity UI

edited December 2022 in Technical Q&A

AC is 1.76.1 and Unity is 2021.2.7f1. I've settled on using these settings:

It works almost as intended. I left click and hold on a hotspot, and the interaction menu pops up. As long as I'm holding the button, it stays up, no matter where on the screen the cursor is (intended). If I release it anywhere else on the screen, the interaction menu is closed (intended). If I release it when the mouse is over the interaction menu but not on any clickable button, the menu stays up (intended). If I then click on the desired interaction, it runs (intended) without closing the menu (also intended, I want the player to be able to click multiple times if the interaction doesn't block gameplay). However, if i release the mouse button when it's over a clickable interaction button, the interaction is not triggered (unintended). It forces me to click on the button.

If I change the source of the menu from Unity UI to Adventure Creator without changing anything else, then releasing the click will trigger the interaction.

(The third button is configured exactly the same as the second, but linked to a different Unity UI button.)

Which brings me to a second issue:

The only reason I'm keeping a couple of buttons with "disabled interactability" rather than "disable object" is that the interaction menu will pop up even when all buttons are disabled, and it looks very ugly if there are no icons in it. Keeping a couple of buttons with disabled interactions looks OK, but ideally, the menu wouldn't pop up at all if all button objects were disabled.

As for item interactions, I'm skipping the interaction menu altogether (the player selects the item and clicks on the hotspot). So ideally the menu wouldn't pop up if the hotspot only had item interactions either.

How would I get around these issues? Are they AC bugs or am I doing something wrong?

Comments

  • However, if i release the mouse button when it's over a clickable interaction button, the interaction is not triggered (unintended). It forces me to click on the button.

    I'll attempt a recreation, thanks for the details.

    the interaction menu will pop up even when all buttons are disabled. That works OK, but ideally, it wouldn't pop up at all if all interactions were disabled.

    The Interaction menu's behaviour is independent of what's inside it. You could either disable the Hotspot itself, or lock the Menu in the event that such a Hotspot is selected.

    ideally the menu wouldn't pop up if the hotspot only had item interactions either.

    You can check Single 'Use' Interaction? in the Hotspot's Inspector to have it emulate the Context Sensitive interaction method, i.e. a one-click interface. Otherwise, having a script that locks the Menu if no Use interactions are enabled should provide this as well.

    Something like:

    using UnityEngine;
    using AC;
    
    public class AutoLockInteractionMenu : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnHotspotSelect += OnHotspotSelect; }
        private void OnDisable () { EventManager.OnHotspotSelect -= OnHotspotSelect; }
    
        private void OnHotspotSelect (Hotspot hotspot)
        {
            bool showInteractionMenu = false;
            foreach (AC.Button button in hotspot.useButtons)
            {
                if (!button.isDisabled)
                {
                    showInteractionMenu = true;
                    break;
                }
            }
    
            Menu menu = PlayerMenus.GetMenuWithName ("Interaction");
            menu.isLocked = !showInteractionMenu;
            if (!showInteractionMenu) menu.TurnOff ();
        }
    
    }
    
  • Thanks, Chris! If anyone else is looking to use the script above, it works best if you switch the last two lines (or else a menu will appear if you click a hotspot with no enabled interactions while the interaction menu for a different hotspot is still on):

            Menu menu = PlayerMenus.GetMenuWithName("Interaction");        
            if (!showInteractionMenu) menu.TurnOff();
            menu.isLocked = !showInteractionMenu;
    

    Also, have you managed to reproduce the other issue I'm having?

  • I have, yes, and am currently looking into it.

  • A fix will be included in the next release.

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.