Forum rules - please read before posting.

Opening the Interactions menu for a specific inventory item by script

edited January 31 in Technical Q&A

Unity 20.4.26f1 AC v1.75.3

Hey, I've been hacking away at the script below and my brain is pretty fried. It does two things -

https://pastebin.com/5gxn1qjK

Spawn a bunch of linked prefabs related to the player's currently held inventory items (which works)

  • pressing the Submit button should open the interaction menu and show the appropriate interactions for the inventory item with the ID defined by currentlySelectedItemID (int).

what's strange is that whilst pressing Submit does indeed open the interaction menu and show the appropriate interactions for the inventory item relating to currentlySelectedItemID, it only works when my other menus related to inventory are not open. I can see in the scene hierarchy that the interaction menu simple isn't being spawned when Submit is pressed (it's using Unity UI prefab) whenever any other AC menu for my inventory is open.

I was wondering if anyone could look at the script and spot something I might be stupidly missing :dizzy:

Thanks!

Comments

  • Does the Debug.Log inside the final Update block (which runs when Submit is pressed) appear, or is it a case of inputCooldown being positive?

    If other Menus are open, do they pause the game? If you want the cooldown to work while pause, use Time.unscaledDeltaTime instead.

  • Hi Chris, thanks for taking the time to get back to me.

    The Debug.Log ("Interactions menu opened - setting item to: " + foundInstance.InvItem.label) you mentioned does indeed appear when pressing Submit when outside of menus, it doesn't when in menus. I can confirm that none of the menus are set to pause game, I've also taken the cooldown out for now to eliminate that as a potential cause.

    I've added the debug line 'Debug.Log("No InvInstance 'foundInstance' found");' to my Update loop if foundInstance is null.

    Now as soon as I open the menus which contain the inventory that line "No InvInstance 'foundInstance' found" is printed to console on every frame.

    It seems that as soon as I open my menu system the following line is unable to find an InvInstance.

    InvInstance foundInstance = GetInventoryInstanceByID(currentlySelectedItemID);

    If I press Submit to open the Interaction menu before any other menu is opened it displays, I can then press the button to bring up my menu and it will stay on screen.

    I am probably not fully understanding how InvInstance works.

    Here's my script with the modifications:

    https://pastebin.com/uD1ZLSHB

  • I'm such an idiot, apologies for not catching this earlier myself :#

    For testing I was using the inventory item ID for the player's Revolver weapon (which is set to carry on start) as the input for currentlySelectedItemID. (I have a bunch of extra logic yet to implement that sets this ID based on spawned items).

    However, when opening the inventory I run a check to see if the player has any ammunition for their Revolver, if they don't then I remove the Revolver item and add the 'Revolver Empty' item which is ID 15. I wrote this logic years ago for my last project so forgot it was executing!

    It was working as intended all along, gah.

    Thanks anyway, as always Chris!

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.