Forum rules - please read before posting.

Equipment window

I've searched around but couldn't find anything, so here goes:
I need a simple "gear" or equipment window where I can put certain inventory items, which will affect character stats, like any RPG (Diablo, Dark Souls etc). It will have a picture of a body, to illustrate where the item is equiped (head, hand, etc).
Basically this is just another inventory window, only I can keep track of which item goes into which slot. As far as I can tell, the built-in AC inventory menu only has a number of slots, but they fill up automatically and don't have individual properties.
I wonder if AC has anything else pre-designed that I can use, or if I'll have to code this with standard Unity UIs.



  • edited August 2021

    As an opening caveat, I should mention that AC itself is intended for traditional adventure games - not RPGs. For a traditional RPG equipment window, custom scripting will need to be involved.

    I would say this is best handled using Containers. A Container is a collection of Inventory items - much like the Player's - only it exists in the scene.

    Starting in just a single test scene for now, create a Container for each body part that the Player can assign an item to. Check Limit number of slots? in their Inspectors, and set the Maximum number of slots to 1.

    Containers are normally opened by using the Container: Open Action. This will default bring up the default Container menu, with the Container chosen in the Action automatically linked to the ContainerItems element in the Container menu.

    What you'll want to do instead, though, is link multiple Containers to multiple elements in your Menu.

    Go into AC's Menu Manager and create your Equipment menu, with each equipment slot being a separate InventoryBox element with its Inventory box type property set to Container.

    You'll then need a script that sets the OverrideContainer property of each element to its corresponding Container in the scene. This is best done in the OnMenuTurnOn custom event, which is run when a Menu is turned on.

    Something along these lines should do it:

    using UnityEngine;
    using AC;
    public class EquipmentMenu : MonoBehaviour
        public Container headContainer;
        public Container handContainer;
        private void OnEnable () { EventManager.OnMenuTurnOn += OnMenuTurnOn; }
        private void OnDisable () { EventManager.OnMenuTurnOn -= OnMenuTurnOn; }
        private void OnMenuTurnOn (AC.Menu menu, bool isInstant)
            if (menu.title == "Equipment")
                (menu.GetElementWithName ("Head") as MenuInventoryBox).OverrideContainer = headContainer;
                (menu.GetElementWithName ("Hand") as MenuInventoryBox).OverrideContainer = handContainer;
                // etc

    Where "Equipment", "Head" and "Hand" are the names of your menu, and head/hand InventoryBox elements respectively.

    Things'll need a bit more tweaking to get it working with Unity UI, and across multiple scenes etc, but have a go with this first and see this approach suits you before we take things further.

  • Thanks a lot!
    Yeah I know this is geared towards pure adventure games, but the equipment window/stat thing is mostly a gimmicky "side" feature, and not a central element of the gameplay. The rest is just dialogues and fairly simple puzzles.

    I'll get started trying out your recommended method right away!

  • Ok, some more things;
    I've done most of the stuff above, but it struck me that I haven't really sorted out the inventory functionality yet, or more exactly how to cycle around the objects - and the left/right arrows - with keyboard/controller input.
    I have arranged it so that one key opens up both the inventory bar as well as the stats window (and pauses the game), but I need to be able to travel around these two windows to put inventory items in the equipment slots, using only keys/buttons.
    I plan to skip the traditional "use inventory on objects in the scene" routine, and only have the equipping of items as puzzle mechanic.

    Moreover, and this just shows that I'm a bit new to this environment, but where do I put the script you showed me? Just anywhere in the scene hierarcy?

  • I need to be able to travel around these two windows to put inventory items in the equipment slots, using only keys/buttons.

    At the top of the Menu Manager, check Directly-navigate Menus when paused to cause any pausing menus to be navigated via Horizontal/Vertical inputs instead of the cursor.

    See the Manual's "Navigating menus directly" chapter for more on this topic.

    If your Menu uses Unity UI, you can specify which element is the first-selected when such a Menu is turned on. Otherwise, the first-defined will be auto-selected.

    If your Inventory and Equipment panels are in different Menus, I'd recommend relying on Unity UI, as Unity UI's "Automatic" Navigation option allows you to navigate across different UI canvases.

    A tutorial on using Unity UI with AC menus can be found here.

    where do I put the script you showed me? Just anywhere in the scene hierarcy?

    For now, yes. If it works in the way you're looking for, you'll eventually likely want to have it be part of a prefab and have it not be part of any specific scene. Here, though, add it to an empty in your test scene, create a couple of Containers, and assign them in the component's Inspector.

    So long as you have a Menu with InventoryBox elements that match the names used in the script, they should be connected with the Containers when the menu is turned on.

  • Roger that.
    Unfortunately, this happens when I try to compile the code:
    error CS0123: No overload for 'OnMenuTurnOn' matches delegate 'EventManager.Delegate_OnMenuTurnOn'

  • Btw: The above error came for both lines
    private void OnEnable () { EventManager.OnMenuTurnOn += OnMenuTurnOn; }
    private void OnDisable () { EventManager.OnMenuTurnOn -= OnMenuTurnOn; }

  • I do apologise. The OnMenuTurnOn event does not require a MenuElement parameter.

    I've updated the above script with the corrected version.

  • edited August 2021

    Ok, I've followed the steps above.
    I still don't know how to navigate the slots using arrow keys, or activate an object using the interaction key.
    Also, suddenly it's no longer possible to disable/remove the whole menu window using the key I've assigned for this function, even though it previously worked just fine to toggle on/off. After I turn it on now, it just stays there, with the game paused, and doesn't respond to the turn-off-key. Strange.

  • edited August 2021

    Ok, an update - nevermind the second part of the above post, the toggling works fine now, it was a sloppy error on my part.

    As for the navigation part, I can now move between the inventory items in the inventory box, but my intention is to "activate" one item, and then jump up to the equipment part of the menu (with the containers), and put it in one of the empty slots there.


  • I must apologise again. Actually, the above script isn't necessary - I'd forgotten that it's possible to map a Container to a specific element using Actions.

    We'll first need to make sure that your Containers are correctly linked to their respective intended elements.

    Remove the custom script, and instead use a pair of Container: Open Actions before turning on your Container menu. For both Actions, check Open in set element?, and then fill in the details so that your e.g. Head Container (again, just in the scene for now) is linked to your "Head" InventoryBox element in your Equipment menu.

    Test that these links are working by assigning a test item in each Container's Inspector, to make sure that these items are displaying in the Menu correctly once it turns on. Once confirmed, remove these test items from the Containers.

    When it comes to clicking on an item in the Inventory to then have the user choose an Equipment slot for it: there's a few ways to go about it. The code-based approach would be to hook into the OnMenuElementClick event to catch the click, record the selected element for later use, and then select the first equipment slot. Let's try it using just Actions, though: create a "Use" interaction for an inventory item, and define an Inventory: Select Action to force the selection of the item, and a Menu: Select Action to have it select the first equipment slot (InventoryBox element) in your Equipment menu. As I said, you'll want to make sure you're either using a single Menu for both your Inventory and Equipment panels, or make use of Unity UI instead.

    Once an inventory item is selected, clicking a Container InventoryBox element will then cause that item to be moved to the Container.

    There's quite a few steps here, so let me know how you go. If you encounter an issue along any point, let me know details of how things are set up and I'll assist.

  • edited August 2021

    I'm stuck on the first step, hehe.
    I think it's a bit unclear where to put the functions. Are there special places for "on game start" or "repeatedly" or something like that, or do I always use the scene->cutscene?
    This is how I attempted it:


  • As an initial test, it can be run in the scene's OnStart cutscene - as at this stage, we're only dealing with a single scene. You do not need to check if the Menu is visible or not, though - the Container will still be linked to the InventoryBox element even if it's not currently enabled.

    Your Actions are not wired up to the first Action, however - they won't be triggered.

    In testing this myself, I have encountered a small issue in that it's actually required that the Menu is off when calling this Action. Before anything else, open up AC's MenuInventoryBox script and find the line:

    overrideContainer = value;

    Immediately after this, paste in the following:

    PlayerMenus.ResetInventoryBoxes ();

    (I'll apply the same fix to the next official update)

    With this change made, the containers can be mapped to the Menu at any time. The best time to do this is actually at the moment the Menu is turned on.

    We can run logic when a Menu is turned on by assigning an ActionList asset file in the Menu's ActionList when turn on property field.

    Recreate the two Container: Open Actions you have in an ActionList asset file, and assign it to run when the Menu is turned on.

    As you're now referencing scene objects via an asset file, you should find that "Constant ID" labels are then showing up in the Actions, and Constant ID components are being assigned to the Containers the Actions reference. This is how AC links asset files to scene objects.

    At the moment, stick to the test scene: the Containers will need to be in your Hierarchy at the moment the Menu is turned on for things to work. Once we've gotten this working, though, we can see about having your Containers present throughout your game.

  • edited August 2021

    Ok, everything in your last post now works, so that's great :)

    So, navigating works fine. However, when I select the item in the inventory, I don't automatically switch to the container with the designated slot.
    Here's my attempt:

  • Keep your "Slot index" value as zero, and are you using the same Menu to display both your Inventory as well as the Equipment slots? If not, are you relying on Unity UI for their display?

  • I changed the slot index to 1 just to try, but changed back to 0 again.
    Yes, both inventory and equipment are the same menu! Still no luck.

    So the selection does indeed travel to the right container slot, but it doesn't swap the item there for the new one, even if I press interact key (use action) again.

  • edited August 2021

    Ok, an update.
    After some fiddling around I managed to get basically all functionality in place (hooray!), however there's this little readability problem left:

    When I navigate the various inventory/container slots, I only get the highlighted version if there's already an item in the box. This means I have to press the arrow keys blindly, until I reach a slot with an item. It also means that once I "use" (interaction key) an inventory item, I don't really see that I'm now in the designated container slot (although if I hit the interaction key again, the item does show up properly.)

    Short version: I'd like the "highlight" texture (let's say a nice frame or a different-coloured background) to show when the element is selected, even if there's no item there.

  • What is your Menu's Source?

    If you're using AC to render your Menu, check Highlight empty slots? in the InventoryBox element's properties to show the highlighted texture even if the slot is currently empty.

    If you're using Unity UI, it's a case of setting your When slot is empty to Clear Content, and configuring the "Disabled" appearance of the linked Button in the UI prefab.

  • I'm using AC as a rendering source, and I'm probably blind because I can't see "Highlight empty slots" anywhere, despite having combed the editor for such a setting all morning...
    I see "Background texture" and "highlight texture" but I don't see the setting you're referring to :(

  • Sorry I wasn't clear. You'll need to make sure that you have Items can be re-ordered in Menus? is checked in the Settings Manager for this option to show.

  • Perfect!
    I'll take the opportunity to thank you for your quick and helpful feedback in this forum.
    I guess next step is making sure this persists across multiple scenes? I think you mentioned that this current setup is a scene-only thing.

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.