Forum rules - please read before posting.

2D Custom Inventory and Held Item Functionality

I'm using unity version 2022.3.20f1, and v1.83.0 of AC.

I'm trying to set up a custom inventory menu a certain way. Rather than it being an active bar on the top of the screen, it pauses the game and takes up the majority of the screen. It looks like this (forgive the shoddy placeholder graphics) https://imgur.com/a/4t2fmEv A holdover from the original inventory menu I've noticed is that you can click and drag items around, which would serve as their 'use' function with the cursor. What I would like to do is to be able to click and drag inventory items into the separate 'held' slot (the box with the hand symbol), which would allow the player to actively hold one item at a time during gameplay to use on other objects in the overworld, in place of the default 'use' function. Right now, when you click and drag an inventory item you can't actually move it to different inventory slots. I can't seem to figure out how to implement this functionality. Also, due to an oversight in my settings, whenever the player picks up an item, it populates into both the first slot in the inventory and the held item slot automatically, since the 'hold' spot is its own separate InventoryBox element on the menu from the other item slots. I really appreciate any advice you have towards figuring this out, since I feel as though a lot of 2D point-and-click games use a menu system similar to this.

Comments

  • The Hold box would need to be a separate InventoryBox element, as you've done.

    If you were going for a one-click interface, where clicking an item automatically selects it, you could set this Hold box to Display Selected Item, and then prevent the cursor from changing when an item is selected.

    If you want to be able to drop an item on this box, however, you'd likely need to rely on custom scripting - since the "selected" item (in AC terms) is no longer the same item shown in the box.

    The box would instead display the contents of a single-slot Container, that you can then use custom scripting to extract when clicking Hotspots.

    Let's sort out the former before tackling the latter.

    Create a new Container, give it 1 slot, and attach the Survive scene changes component. Make it a prefab, remove from the scene.

    Then, in the Events Editor, define a Scene / Begin game event that runs an Object: Add or remove Action that spawns this prefab in when the game begins regardless of starting scene.

    Set your Box's Inventory box type to Container, and - in the Menu's ActionList when turn on asset - run a Container: Open Action and reference the prefab. Check Open in set element? and enter the details of the Menu / InventoryBox to display it in.

    You can test this is working by giving the Container a starting item, and checking it shows when turning on the Menu.

  • Right now, when you click and drag an inventory item you can't actually move it to different inventory slots.

    If you want to be able to move an item between slots in the same InventoryBox, check Items can be reordered in Menus? in the Settings Manager.

  • Thank you so much! I followed your instructions and it works exactly how I wanted it to. I'm very grateful for how often you respond on the forum, I genuinely don't think I would've been able to make actual progress on my game without your help.

    I had one or two follow-up questions about this feature. I would like whatever object is in the held slot to also appear in the player's hand in the overworld. I was able to figure this out 80% of the way on my own, but its not perfect. Using the events editor, I created an actionlist for an 'OnContainerAdd' event. The action list teleports the item to an empty transform, which is a child object of the player's hand bone, and then parents the item underneath it. During gameplay, regardless of the animation, the item appears to be in the player's hand. This works correctly, however I feel like there is an oversight with the 'OnContainerAdd' event, since I don't know if I can specify this event to only occur when an item is added to that particular container connected to the held item slot. I wouldn't want this to be triggered when any item is added to any container during gameplay. Another problem I realized is that the actionlist is set up in such a way that it only pulls that specific test item in the game to be teleported and parented. I'd want this function to be generalized to call whatever item would be in that held slot, regardless of what it was.

  • The Event itself will run for all Containers, but its ActionList includes a Container GameObject parameter that will be set to the affected Container. You can begin the list with an ActionList: Check parameter Action to compare it with your prefab.

    The second parameter it includes is one for the added Inventory item. Use this to override the Object: Add or remove Action's Object to instantiate field. This will cause the Item's Linked prefab asset to be added to the scene.

    If you create a second GameObject parameter, you can have this Action assign it as the spawned item. You can then use this new parameter to override the Character: Hold object Action to place the spawned item in the Player's hand (provided you've set up the hand Transforms in their Inspector).

  • Hi Chris, I made these changes according to your instructions. The first part works great, but I'm having a bit of problem getting the second part to work. When I create the Object: Add or Remove action, I cannot actually use the 'inventory item' parameter to override the Object to instantiate. My only options I can choose from are the container parameter, or the second GameObject parameter I created according to your instructions. I thought this might be caused by the 'inventory item' parameter not being set, so I put a 'Set parameter' action ahead of it in the action list, and this didn't fix it. Goes without saying, but any help is appreciated.

  • Odd. You say you're in v1.83.0?

    Try taking a backup of your project and import the latest release - does it give you the option then?

  • edited October 27

    Hi Chris,
    I backed up my project and updated to AC v1.85.0. Still using the same version of Unity. Going back to the Event Editor after a long break, I need some help ironing some things out, in regards to setting items from the held slot to be held by the player.

    For context, in my project, when an item is picked up by the player, and the object is added to the player's inventory, it's GameObject counterpart is not removed from the scene, but rather teleported out of sight to a marker that sits outside of the game's boundary. I'm not sure if this is a preferred method, but I did so on the recommendation of a tutorial video.

    Therefore, in the OnContainerAdd actionlist, I don't think I should instantiate that gameobject again, since it already exists. Unless this is necessary to locate the GameObject equivalent of its inventory item counterpart. Here's an IMGR link to what my actionlist looks like: https://imgur.com/a/okay-ZNna1ik

    You can understand what I'm trying to accomplish with this. I want to somehow 'find' whatever object was put into that container, and then set the object to be held by the player.

    Any help is appreciated.

  • If you're looking to show the given Item in the Player's hand, you'll want to remove the original from the scene and spawn them in as a separate object. This'll give you the freedom of it being able to work across scenes, and independently of what objects were originally in them.

    AC has a dedicated means of spawning Inventory items into the scene via its Inventory: Scene item Action. This let's you spawn in the associated prefab of a given Item, while also retaining any property values unique to it.

    In your OnContainerAdd event, try using this Action instead of Object: Add or remove to spawn it in. You can use the Inventory Item parameter to override which Item is referenced.

    At the bottom of this Action, you can also assign your ActionLists 2nd GameObject parameter, which will cause it to be set automatically to the Scene Item object that was spawned.

    A tutorial on Scene Items can be found here.

  • I tried using the Inventory: Scene Item action and followed your tutorial to the best of my ability, but I've encountered some hiccups.

    In the 'Use' Actionlist for that game object, (the one that removes it from the scene and puts it's inventory item counterpart into the inventory) I tried using 'Scene to Item' to accomplish this, and when tested it does nothing. I made sure 'Remove original' was selected. The item is neither removed from the scene, nor is it put into the inventory. There were no error messages in the console log, and when I put a dialogue action after it to test if the first action is failing, the dialogue plays.
    The same thing occurs regardless if the item in question is being called directly, or if I override it with a parameter set to that object, like in the tutorial.

    Strangely, however the 'Inventory: Item to Scene' function works perfectly fine, within the OnContainerAdd Event that controls sending the inventory item into the scene to be held. I selected 'carry on start' to test this, since currently it's not possible to pick up that item from the scene. It starts in my inventory, and when I put it into the hold slot, it's successfully instantiated into the scene and held by the player.

    The 'Use' Actionlist functions normally when it has Object: Add or Remove paired with Inventory: Add or Remove, but as you've said this is not the preferred method. Not entirely sure why it's behaving this way.

  • Double-check that the Console isn't suppressing Warnings - if anything fails with the Action it should get reported.

    In a backup/duplicate project, try this with the latest release. If you can share any screenshots of the Action, I'll see if I can spot anything amiss.

  • Hi Chris, I've updated to AC 1.85.1 and solved the issue.
    (Also I failed to mention in the last message I updated to Unity 2022.3.62f2)
    I was working under the assumption I had successfully added the 'RememberSceneItem' component to the item's prefab, but when I double -checked I had not. I probably added the component and then exited prefab mode by running the game, without saving. After adding that, it works perfect now.

    With that fixed, I was wondering if there was a way to set up my OnContainerAdd Event so that it could be generalized to any item that is added to the inventory. Right now, the way that is formatted is to move the default test item, the apple, and only that item.
    See here: https://imgur.com/a/oncontaineradd-event-EXr17A0
    I tried experimenting a bit, but I couldn't figure out just which action could detect what item was placed in the container, in order to save that item to a parameter.

    I also created a OnContainerRemove Event, that works similarly. It's still using the apple as a default, but I'd also like to generalize that as well.
    See here:https://imgur.com/a/oncontainerremove-zsp9uN4 (As a note, the reason I'm not using Scene To Item here, is that the original item is never removed from the inventory when placed into the 'hold' container.)
    Any help is greatly appreciated.

  • If your ActionList contains an Inventory Item parameter, the "Container: Add" and "Container: Remove" events can be configured to set this parameter to the Item that was added.

    You can then override Inventory item fields in Actions with this parameter - click the "P" beside "Apple" in your screenshot.

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.