Forum rules - please read before posting.

Question about hotspot interactions via inventory

Sorry if this is explained somewhere but I’m struggling to find the right terms to describe what I would like to do, which makes searching hard:

My inventory is based on resident evil’s and so when you select an item, a little sub menu pops up with some options to discard, combine/move the item, or you use it. (Thank you so much for your awesome suggestions in getting that and the little descriptions and closeup images working using event listeners, btw)
When you select use, I am wanting to detect whether the player is in a hotspot, and more specifically whether that hotspot has an interaction with that item (or vice-versa I guess)
If not, an unhandled interaction / generic “you can’t use that here” subtitle would play, whereas if it is possible to use the item with the currently active hotspot (they are detected by colliders around them and player vicinity) I’d want whatever the interaction is to happen.
I had a play with action lists but I couldn’t quite find the right one so figured it would be easier to do through script.
I guess what I’m asking for is the right way to check for valid inventory interactions based on the currently active hotspot.
whether that’s better done by changing the “use” interaction of an item when you enter a hotspot, or having the hotspot be detected when the use option is selected is probably up for debate, but I’d assume the latter is how most games would handle it right?

Hopefully that makes sense!

Comments

  • One quick thought I had was that this should only apply to items that don’t have a use function by themselves, so not weapons, healing items or anything you can use to change into something else or what have you.
    Therefore would it make sense to check to see if an item has a use interaction assigned first, then check for the closest hotspot, THEN either run the hotspot interaction or play a generic unhandled interaction action?
    I figured you can detect the nearest hotspot with KickStarter.player.hotspotDetector.NearestHotspot; but I’m not sure how to both check whether the currently selected item has its own use action assigned, nor whether it has an interaction with the hotspot I’ve detected.

  • edited March 2021

    Assuming you already have a reference to the given item instance, the code checks would be:

    if (invInstance.InvItem.useActionList == null)
    {
        // Item Has no "use" interaction of its own
        Hotspot nearestHotspot = KickStarter.player.hotspotDetector.NearestHotspot;
        if (nearestHotspot)
        {
            // Hotspot is nearby
            if (nearestHotspot.HasInventoryInteraction (invInstance.InvItem))
            {
                // Hotspot has an associated inventory interaction
                // Run the Hotspot/Item interaction
                nearestHotspot.RunInventoryInteraction (invInstance);
            }
            else
            {
                // Hotspot has no associated inventory interaction
                // Run the Item's unhandled Hotspot interaction
                invInstance.InvItem.unhandledActionList.Interact ();
            }
        }
    }
    

    A slight tweak if your Inventory interactions setting is set to Multiple: Replace:

    if (invInstance.InvItem.useActionList == null)
    

    with:

    if (invInstance.Interactions.Length == 0)
    
  • Radical! Thanks heaps. Trying hard to get my head around all the stuff on the wiki but I’m a pleb at scripting so really appreciate the help!
  • edited March 2021

    Sorry - typo on the last line above. "> 0" should have read "== 0".

  • Hi, sorry to dredge this up, but I'm curious as to how you'd recommend I run this script. I can attach it to the unity button that does the "use" function, and have it run as an event, but would it be better to instead have it linked through AC's menu button "onclick" setting? I'm worried I'll balls something up if I have a weird mixture of unity and AC both controlling things!

  • AC has it's own EventSystem to handle mouse-driven vs directly-navigated menus - mainly to ensure that things like click inputs (InteractionA etc) are consistent.

    Though, a UI Button in an AC Menu isn't strictly required to be linked to an equivalent AC Button Element. While the usage of UI scripts will vary between projects, there shouldn't be any inherent issue with mixing them like that. I'd say that'd only be something to deal with if you encounter an issue.

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.