Forum rules - please read before posting.

Can you reference calling inventory item inside a custom action script?

I'm working on a system to show a 3D viewer for inventory items when the player 'Examines' them. I noticed there's already an API call for storing a reference to a prefab, but does the API allow for a way to reference the inventory item that calls the 'Examine' script inside of a custom action script?

I figured this way I'd only need one action list with a custom action script instead of one action list per each inventory item. Then, when the player examines any inventory item, I could open my 3D viewer menu, (get the inventory ID), use the ID to get the prefab, then load the prefab into the viewer.

Thanks!

Comments

  • Shoot, posted too soon and found this in the scripting guide already.

    I think the way to do this would be to call "lastClickedInstance". I can just open my 3D viewer menu, then check lastClickedInstance for the instance of the inventory item.

    https://www.adventurecreator.org/scripting-guide/class_a_c_1_1_runtime_inventory.html#af4e15e73a7a8b2825900129f2b315079

  • Sorry to keep following up on my own thread... It looks like, 'lastclickedinstance' only counts for the primary click (select), not secondary (examine).

    Is there a way to see the last 'examined' item in the same way?

  • If you're using a shared ActionList asset for multiple Inventory item Examine interactions, and then an "Inventory Item" parameter to control what's affected, then you can assign the parameter dynamically using the Set Inventory Interaction Parameters component.

    (Note: If you're using an "Object: Add or remove" Action to spawn the linked prefab, you can use an "Inventory Item" parameter here to have it reference that item's prefab.)

    For each item involved, attach this component to a GameObject in your scene (can be the same object), match its Inventory item field and set its Interaction type field to Examine. You'll then be able to assign that same item in the parameter box beneath.

    This object could then be made into a prefab in each scene, or attached to a persistent object such as a custom EventSystem.

    Alternatively, a custom script can hook into the OnInventoryInteract_Alt custom event, which runs when an item is clicked and provides the clicked item and interaction ID as parameters.

  • That's awesome, perfect, thank you for responding with such a detailed answer, that's exactly the info I needed! I especially like the first option, I try to work within the AC framework as best as possible for any extensions.
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.