Forum rules - please read before posting.

Cannot drag item from inventory or click on hotspot (using custom interaction)

budbud
edited January 2023 in Technical Q&A

Upgraded to latest version 1.76.1 from version 1.75.4

Main Issue:
Cannot drag item from inventory it just moves the screen (drag), AND cannot click on hotspot, nothing happens.
NOTE: This worked fine using v.1.75.4, but not with 1.76.1 with the same settings !!

I use a custom method for dragging from inventory and clicking hotspots
On Start() I do: KickStarter.stateHandler.SetInteractionSystem(false);
In Update() I use the following to detect hotspot:
if ((Input.GetMouseButtonUp(0) || (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Ended)) && KickStarter.stateHandler.IsInGameplay() && KickStarter.playerInput.GetDragState() == DragState.None)

  • raycast hit => hit.collider.gameObject.GetComponent().RunUseInteraction();

And this to detect inventory interaction:
if ((Input.GetMouseButtonUp(0) || (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Ended)) && KickStarter.stateHandler.IsInGameplay() && KickStarter.playerInput.GetDragState() == DragState.Inventory)



Another issue:
This issue is for both versions 1.75.4 and 1.76.1
When clicking on a Unity GUI button, the GUI button triggers, but in addition also the hotspot behind the GUI button is triggered.
Setting: "Unity GUI blocks interaction and movement" is set to True.
What could be the reason for this, and more importantly, how to fix this ?

Comments

  • Cannot drag item from inventory it just moves the screen (drag), AND cannot click on hotspot, nothing happens.

    By "moving the screen", is this a reference to your camera being a "GameCamera 2D Drag"?

    As you're using a custom script to handle input, tempoarily remove it and see if it works with AC alone.

    If so, you'll need to share more of your code so that I can recreate the issue.

    When clicking on a Unity GUI button, the GUI button triggers, but in addition also the hotspot behind the GUI button is triggered.

    What effect does the Button have, is it Button linked to AC's Menu Manager, and - if so - have you assigned a suitable "RectTransform boundary"?

  • budbud
    edited January 2023

    --- Hotspot not reacting ---

    Look at the video above, doors and Christmas tree has hotspots.
    When I tried a lot more using the custom script method, I actually found out that clicking very quick (very short press) it did work, but when not clicking very quick (pressing down longer), nothing happens. Perhaps some adjustment here ?
    Also using AC, witch means disabling the custom script and setting hotspot ray length back to 20, did NOT work at all, regardless of click press length!

    Code:
    using UnityEngine;
    using AC;

    public class ClickUpInteract : MonoBehaviour
    {
    public float rayLength = 20f;

    private void Start ()
    {
        KickStarter.stateHandler.SetInteractionSystem (false);
    }
    
    private void Update ()
    {
        if ((Input.GetMouseButtonUp (0) || (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Ended)) && KickStarter.stateHandler.IsInGameplay () && KickStarter.playerInput.GetDragState () == DragState.None)
        {
            Ray ray = Camera.main.ScreenPointToRay (KickStarter.playerInput.GetMousePosition ());
            if (Physics.Raycast (ray, out RaycastHit hit, rayLength, 1 << LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer)))
            {
                Hotspot hitHotspot = hit.collider.gameObject.GetComponent<Hotspot> ();
                if (hitHotspot)
                {
                    hitHotspot.RunUseInteraction ();
                }
            }
        }
    }
    

    }

    --- GUI Button ---

    I have not added buttons to AC Menu Manager.
    Is there a way to block GUI without adding to Menu Manager ?

  • edited January 2023

    Look at the video above, doors and Christmas tree has hotspots.

    Apologies for the trouble - but rest assured, we'll get to the bottom of it.

    I've recreated your settings and tested your script, and it's working OK on my end - at least in the Editor.

    Is the issue occuring for you in the Editor, or only in builds?

    As the issue may be down to some key setting unique to your project, it may be easiest to see the same project for myself. You're welcome to PM me a link to download your project from, with instructions on how to see the issue. This can be a cut-down project (ie. one with only a single scene, and no Library folder) to help reduce file-size.

    Is there a way to block GUI without adding to Menu Manager?

    The Unity GUI blocks interaction and movement? option you mentioned should handle this, but only if you're using AC's built-in movement and interaction systems.

    If you're using your own script for these systems, you can use a simplified copy of the same function that AC uses:

    bool UnityUIBlocksClick ()
    {
        #if !UNITY_EDITOR
        if (KickStarter.settingsManager.inputMethod == InputMethod.TouchScreen)
        {
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                if (KickStarter.playerMenus.EventSystem.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
                {
                    return true;
                }
            }
            return false;
        }
        #endif
        return KickStarter.playerMenus.EventSystem.IsPointerOverGameObject ();
    }
    

    To use it, copy/paste into your script, and read the state of UnityUIBlocksClick() before processing movement/interactions.

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.