Forum rules - please read before posting.

Make hotspot within Inventory - drag item onto EXAMINE

Hi there,

Been struggling with this for a while. I want to be able to drag an item in the inventory to an area called EXAMINE which will trigger an action list. I've played around a lot with menus trying to find a way to do this but without any luck. If I could have a hotspot within a menu, that would solve it. Is that possible or is there another way?

My game interaction is Context Sensitive.

Here is a mockup to show what I am after: https://imgur.com/LxsTTqy

Massive thanks.

«1

Comments

  • edited March 2019

    You'd need some custom scripting, but likely not too much.

    Create a menu/button element to display "Examine", and set its Click type to Custom Script. You can then hook into the OnMenuElementClick custom event to examine the currently-selected item when clicked on:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class MenuEventTest : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnMenuElementClick += My_OnMenuElementClick;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuElementClick -= My_OnMenuElementClick;
        }
    
        private void My_OnMenuElementClick (Menu menu, MenuElement element, int slot, int buttonPressed)
        {
            if (menu.title == "ExamineMenu" && element.title == "ExamineButton" && KickStarter.runtimeInventory.SelectedItem != null)
            {
                KickStarter.runtimeInventory.SelectedItem.RunExamineInteraction ();
            }
        }
    
    }
    

    (Replacing "ExamineMenu" and "ExamineButton" as appropriate)

    That should trigger an examine interaction when the button is clicked. If you want to make use of drag-and-drop, you could instead hook into the OnInventoryDeselect event and check if the mouse is over the button:

    using UnityEngine;
    using System.Collections;
    using AC;

    public class InventoryEventTest : MonoBehaviour
    {

    private void OnEnable ()
    {
        EventManager.OnInventoryDeselect += OnDeselectInventory;
    }
    
    private void OnDisable ()
    {
        EventManager.OnInventoryDeselect -= OnDeselectInventory;
    }
    
    private void OnDeselectInventory (InvItem _item)
    {
        Menu menu = PlayerMenus.GetMenuWithName ("ExamineMenu");
        MenuElement element = menu.GetElementWithName ("ExamineButton");
    
        if (menu.IsPointerOverSlot (element, 0, KickStarter.playerInput.GetInvertedMouse ()))
        {
            _item.RunExamineInteraction ();
        }
    }
    

    }

  • Hi Chris,

    Thanks for this. I actually need to make an action list run so I can trigger a zoomed in shot of the item, not the standard examine description. However reading your reply sparked an idea which does what I need only using a simple Action List.

    I made an element button in the Inventory as you stated. Then I run an action list when clicked. In the action list I check for specific item selected and then if condition is met I can trigger the zoomed in shot.

  • ...and on this subject, how would I hide ALL elements in a menu? I can see how to hide single elements, but is there something to enter to hide all?

    Thanks.

  • Hiding all elements would really be akin to just closing the menu.

    You can't hide all elements in a single Action, but a series of Actions could close them individually in turn. You can also script it:

    Menu myMenu = PlayerMenus.GetMenuWithName ("MyMenu");
    foreach (MenuElement element in myMenu.elements)
    {
        element.IsVisible = false;
    }
    
  • Thank you!

    Closing the menu would work, but the elements are still visible when it is opened again. Script looks like the way to go.

  • edited March 2019

    Hi Chris,

    My version of your script looks like this:

    https://imgur.com/squBFB5

    and I am calling it at the end of an Action List triggered by clicking a button within the said menu:

    https://imgur.com/6kVKWLx

    Nothing is changing visiblilty.

    What am I doing wrong?

  • You've placed the code in a function named "Start", which will run when the scene begins. You're also not triggering any function within your Action.

    Replace "void Start()" with "public void HideAll()", and you'll then be able to select "HideAll" in the Action where it currently says "No Function".

  • edited March 2019

    I replaced "void Start()" with "public void HideAll()" but I'm not seeing a HideAll action.

    https://imgur.com/PHj3oqg

  • Don't assign the script directly. Attach the script to a GameObject, and assign the GameObject into the left field.

  • I have the script as a component of a game object now, but I cannot drag that game object into that said left field. It won't allow me to.

  • Are you doing this in an ActionList asset, or a scene-based one such as a Cutscene?

    If an asset, you can only do this from a prefab - try dragging the GameObject into your Assets folder and then assigning the prefab instead.

    Alternatively, you can use the Object: Send message Action, setting the Message to send as Custom, and the Method name to HideAll.

  • Awesome. Working with the Send Message version. Thanks Chris!

  • Good evening! Has anything changed in the code regarding the script in the top of this post? I tried this aproach for an examine menu button today, but it doesn't work, unfortunately. :)

  • The code should still be valid in the latest release.

    Though, it assumes that you're using "Single" inventory interactions - is this the case? If so, you'll see an explicit "Examine" interaction field in your Inventory item property boxes.

  • Aaaah that's what I seem to have missed. I'm not using "single" inventory interactions. I have to make it work in another way. At first I thought I'd add an examine Hotspot to each inventory slot, but while I was doing some research on how to approach that solution and ran into this thread and liked the "examine" button.
  • I tried to set it up like this, but it didn't work:
    KickStarter.runtimeInventory.SelectedItem.RunUseInteraction(iconID: 2)

  • Reference the _item variable used by the function - SelectedItem may be null at the time it's run, i.e.:

    _item.RunUseInteraction (2);
    
  • Thanks -as always- for your time, Chris! Sorry for bothering you again but unfortunately something else doesn't seem to be right. After a few tries I set everything up as "single" inventory interactions like in the first example script (figured I won't be needing multiple ones anyway) and tried running it with the first mentioned RunExamineInteraction() script, but it still doensn't work.

  • Are you getting any related messages in the Console? Try placing in a Debug.Log statement under that line in the code to confirm it's being run.

    I'll need to see the wider context. Can you share your Settings Manager, your Menu, and a typical item that should be interacting?

  • edited January 11

    Looks like it's not running. Implemented Debug.Log.
    These are the settings:

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.