Forum rules - please read before posting.

Inventory interaction on direct control

edited March 22 in Technical Q&A

Hello everyone!

I'm currently considering reworking the interaction system of my game to provide a little bit of extra depth for the player. In my current setup, a correct item is automatically used from the inventory (using action inventory:check) which triggers the correct interaction on a hotspot. I'm using direct control with hotspot detector, and I have just one button (InteractionA) for all the interactions. I'd like to change this a bit, but I don't know where to start. I have a second button (InteractionB) to open the inventory. Is it possible to have the inventory button work so that when the inventory is opened on hotspot, an item selected with InteractionA would then be used on the hotspot? Currently "selecting" the item in the inventory fires a use interaction, but it would be cool if the players could actually use the items themselves rather than them to be automatically selected. I'd like the setup to work so that the current use interactions would be triggered when the player is not on an hotspot.

Hopefully this makes sense :smiley:

Comments

  • So that I'm understanding correctly: an Item has a "Use" interaction, but you'd want to override this when clicked if you're over a Hotspot, and use it with the Hotspot instead?

    You'll first need to change it so that the Use interaction is no longer run by default. You can do this by checking the InventoryBox element's Prevent interactions? box.

    Then, use this script to handle the automatic use-with-Hotspot behaviour:

    using AC;
    using UnityEngine;
    
    public class AutoUseItems : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnInventorySelect_Alt += OnInventorySelect; }
        private void OnDisable () { EventManager.OnInventorySelect_Alt -= OnInventorySelect; }
    
        private void OnInventorySelect (InvCollection invCollection, InvInstance invInstance)
        {
            Hotspot[] hotspots = KickStarter.player.hotspotDetector.GetAllDetectedHotspots ();
            Hotspot hotspot = hotspots.Length > 0 ? hotspots[0] : null;
            if (hotspot) hotspot.RunInventoryInteraction (invInstance);
            else invInstance.Use ();
        }
    
    }
    
  • I explained myself poorly, apologies. This is almost what I need. The way I have currently rigged everything is as follows:

    When the player activates the hotspot pressing InteractionA, Inventory:check action is triggered, and if the player is carrying required item, it's used automatically. What I'd like to happen is that pressing InteractionA on hotspot would trigger just examine type of interaction, but the player would need to use the item on hotspot by opening inventory inside the hotspot collider and selecting the correct item. It would be super awesome if it would be possible to use a duplicate menu for the inventory inside the collider which I could rename as "use" or something like that. The inventory items themselves could have the regular use interactions, but inside the hotspot collider items could be used on the hotspot by pressing InteractionA while the inventory is open.

  • Cosmetic changes aside, I'm not sure I understand how your explanation differs from the intent of the above script.

    The script won't affect the Hotspot - so you can set your Hotspot's Use interaction to ignore anything to do with Inventory. The script will combine a selected item with the active Hotspot - but if no Hotpost is nearby, the item's Use interaction will be run as normal.

    If you're looking to have a dedicated "Inventory" menu pop up when dealing with a Hotspot, however, you might want to consider use of an Interaction menu.

    See the 2D Demo for an example - clicking a Hotspot brings up a list of Interactions - both the Use interactions of a Hotspot, but also Inventory interactions.

    It would be possible to tweak things such that Use interactions don't appear here, and clicking a separate input causes the Hotspot to run its default "Use" interaction.

  • Okay, could you help me out a bit on how to set this up and what actions on which action lists to use. I'm a bit confused on how this should work. I currently have the following:

    A hotspot which has a "use" and "inventory" interactions. The "use" action includes Dialogue action where the player states noticing the hotspot.

    The "inventory" action does the following:
    Closes the inventory menu
    Checks the selected item (Form in this case)
    If Form is selected Dialogue action is performed which states "I'm using the form"
    If Form is not selected Dialogue action is performed which states "I'm not using the form"

    The Form in inventory has been setup as follows and has two action lists:
    It has Use interaction which runs Dialogue action: "It's a complaint form"
    It has Use on Hotspot interaction which runs Inventory: select action and selects the Form as an item.

    When I try to run this, only the action on Inventory: check selected, condition is not met is triggered. What am I doing wrong and how do I set this up correctly?

  • Haha, turns out I was thinking about this the wrong way. I was able to set this up correctly just by adding the inventory interactions to the hotspots. Now everything works just perfectly! Thanks for your help!

  • Cheers Chris & community! I'm returning to this with a question: Is it possible to use two different menu graphics depending on has the user opened the inventory over a hotspot collider or not? I'd like to display a "Inventory" text sprite when the user is not over a collider and "Use" sprite when the user is on top of one. These would be sprites on top of the inventory menu. Would be cool if this would be possible.

  • You can use the Events Editor - available in the top toolbar - for this.

    First create a Global Bool variable named e.g. "Is Over Hotspot", and then create a pair of events - Hotspot: Select and Hotspot: Deselect - that set its value to True and False respectively.

    You can then check this variable's value to alter your Menu (e.g. show/hide a given element) as necessary.

  • edited April 10

    Thanks! I probably need to upgrade AC first, because I can't seem to find the menu on the toolbar. I'm using 1.77.3. I'm a bit hesitant to upgrade AC at this point as my game is in alpha, any way this can be done with script?

  • Yes - Events can be set either in the Editor (since v1.78) or through script:

    using UnityEngine;
    using AC;
    
    public class HotspotEvents : MonoBehaviour
    {
    
        public ActionListAsset onHotspotSelect;
        public ActionListAsset onHotspotDeselect;
    
        private void OnEnable ()
        {
            EventManager.OnHotspotSelect += OnHotspotSelect;
            EventManager.OnHotspotDeselect += OnHotspotDeselect;
        }
    
        private void OnDisable ()
        {
            EventManager.OnHotspotSelect -= OnHotspotSelect;
            EventManager.OnHotspotDeselect -= OnHotspotDeselect;
        }
    
        private void OnHotspotSelect (Hotspot hotspot)
        {
            onHotspotSelect.Interact ();
        }
    
        private void OnHotspotDeselect (Hotspot hotspot)
        {
            onHotspotDeselect.Interact ();
        }
    
    }
    
  • Massive thanks! Everything works now great!

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.