Forum rules - please read before posting.

Switch between InventoryBoxes

edited June 2017 in Technical Q&A
Hello!

I'm using AC version 1.57. Unity version 5.5.1f1.

In my game, I want to have a menu with a lot of tabs (or buttons) and a central body containing the items (a inventoryBox with, say, capacity for 9 items).

I want that, if I press on the "Food tab", then the inventory box will show the food category, if I press the "Tools tab", then it will show tool category items, and so on. I do not know which is the best way to tackle this though.

So I tried to do this by having one Inventory menu (using unity UI) with a bunch of InventoryBox elements, all of them hidden except the default one. Then, using a button and an actionList linked to it, I would call Menu: Change State - Show/Hide menu element on said action list to switch between the multiple inventory boxes.

Right now I have my unity canvas with 2 grid elements, 9 slots each. One of these has its 9 buttons linked to the first InventoryBox (category: Food), the other has its 9 buttons linked to the second InventoryBox (category: Tools).

But it doesn't work. What should I do to manage this change? Should I change the way I'm tacking this?


***What I want to do is almost exactly what the poster in this thread   http://www.adventurecreator.org/forum/discussion/5068/multiple-inventory-boxes-change-visibility-via-script  wanted, except that I'm not using scripting, but an actionList (although If it was the only way, then I would switch to scripts)

Comments

  • edited June 2017
    Are you using mouse and keyboard? The reason my method in my post was getting complex at the time, was due two 1. I was still a very rookie programmer (if I do it again, I'd do it much better and simpler), and 2. I needed it to work right for Keyboard only controls and I had some very specific requirements. I also realize now that the issue I was having with all the inventory boxes at that time, which were all showing the same button references , was a serialization issue (I wouldn't have though of that then).

    Anyway, I digress, if you are using your mouse you can rely on Unity to help you with tabbing too, you could do something like this. Or, you could simply do something similar to what you tried but instead of keeping one inventory with multiple inventory boxes, try multiple inventory menus (with same design), each with its own unique inventory box, then just switch menus without using any fading, the change will be so fast, the player won't notice the difference (the technique is pretty much the same either way).
  • Whenever a problem arises with a Unity UI-based Menu, the first thing you should always do is switch its source back to Adventure Creator.  This will help you determine if it is an issue with AC's base Menu system, or with the link between it and Unity UI.

    Alternatively, you could try using an Animator component to show / hide (i.e. move in and out of view) the elements manually.  When AC links an element to Unity UI, it won't control the position - so you can change that yourself through animation.  If you then create an Animator parameter that can be used to control which tab is open, a simple Object: Animate Action could then be used to modify it.
  • Alverik 

    Yeah, the thing is I wanna avoid the multiple menu for the same reasons you gave back then: It is cluttering and it seems not to be the optimal solution (definitely not scalable). I want one menu and multiple inventoryBoxes that are all positioned in the exact same place, and change which one is visible by pressing a button. I'm not using keyboard for the switch between inventory boxes though.


    I will try that, and also a couple more things. But maybe I should change my question to this: Is it posible, let's say using AC menus, to have a single menu with many invBoxes and switch between one another using buttons on that menu? Or is it better to just duplicate the menus and have each only with one inventory box?


  • edited June 2017
    ChrisIceBox 

    Forget about my previous post (tried to edit it but the site won't let me for whatever reason). I managed to advance in my setup and instead wanna ask if you maybe know why the following is happening:

    So I made inventory menu with 2 inventory boxes. I have two buttons, each points to an action list which, in turn, hides or shows the corresponding inventory box. Here are the images of this setup:

    image
    this is my first inv box. All of its slots were linked to a grid panel's buttons, and it only shows the category tools.


    image
    Second inventory box. Its slots are linked to a different grid panel's buttons with different constant ids from the other grid, and it holds inv category weapons.


    So when I start the game and open my inventory, it shows me the content of the first inventory box allright (yeah, the worm and bottle are tools in this example)
    image


    Those two small ugly buttons in the top left (the ones that read Button and Button) are the ones linked to the two inv boxes. the first is linked to invBox1 and the other to invBox2. Here are the action lists linked to both buttons:



    image
    This one is linked to the top button. It is supposed to show the invBox1 and hide the invBox2.


    image
    This one is linked to the second button. It shows the second invBox and hides the first.


    But when I press on the second button, this happens:
    image
    The weapons (the bow and the grenade looking object) appear, but the "tools" (pliers, worm and bottle) stay there visible.


    If I now press the first button, it works as it should (or at least it seems to do). This happens:
    image
    So yeah, it hides the weapons and shows the "tools".


    So this is my problem right now. Ideally at some point, I will have 5 inventoryBoxes on this menu, and be able to jump to each using the buttons. I know that since I'm using Unity's UI I should check with AC first, but I'm only posting this in case there is a brutal visible error in this images that you can see and which I have missed.

    Thanks in advance!!!!


    EDIT**** I have a new insight: Created a third inventory box which holds another category. This time, I realize that the buttons 2 and 3 manage to hide each other, but fail to hide invBox1. Meanwhile, button1 manages to hide both 2 and 3 and show 1. So this is a problem of not being able to hide the first inventory box. I do not know if at some point I set it to be a default or anything, but I believe the issue has something to do with that.
  • If InvBox2 and InvBox3 are both working, then there's likely some difference in the way InvBox1 is set up on the Unity UI side of things.  Check again for any difference however minor there may be.  Let's see an image of your UI's Hierarchy.

    But again, switch your Source back to Adventure Creator to confirm that this isn't an issue with AC's Menu system.  That will help us narrow the problem down.
  • edited June 2017
    Ok, did what you said and it definitely is something to do with Unity's UI, since AC works ok.

    Anyway, just In case someone sees something I do not, here are the screenshots of my UI prefab in the hierarchy window:


    image
    In blue is the relevant part. I know it looks really cluttered, It actually was not like this until I realized I would need 2 shift buttons for each grid so I placed them in a panel.


    image
    Here is my first grid. All buttons have Constant Ids. the grid too (I only put it there to see wether it fixed something. it did not)-


    image
    Second grid. It was a duplicate of the first, but I changed every constant ID so that none is duplicated.

    Finally, here is the two grids in the inspector panel. They are exactly the same except for the position I think.

    image


    image

    Again, I'm only posting in case someone sees something I'm not (maybe I'm making an idiotic mistake here).

    Thanks in advance!!



  • edited June 2017
    What about the third inventory box you created which was working?

    Again, this may be easier for you to just PM me the Menu Manager, Canvas prefab and related ActionList assets for me to see myself.  Package them up in a .unitypackage file and I'll take a look.
  • edited June 2017
    Thanks a lot, but for now I'd rather not waste your time with that. I'll stick to AC menus and try to see what's wrong with the others myself for the time being (if in a while I do not find the solution I'll maybe come back and bother you a bit haha).
  • edited January 2021

    Had a very similar issue...and I discovered it was because of how AC performs "Hide menu element" action on inventory boxes. If "When slot is empty" is set to "Clear content" it will still display empty menu slots even after you hide the menu element. @ChrisIceBox is this intended behaviour?
    However I still wanted to keep it that way because in my setup "Disable object" changed position of menu slots depending on how full the inventory box was.
    The way I solved it was by setting Empty slot texture to none and creating dummy empty slots that were always displayed when Inventory menu was enabled while setting their layer order lower than that of inventory boxes.

  • I would need more details. You're saying that elements are showing even after using the "Menu: Change state" Action to hide them?

    Please create a new thread with screenshots showing your set up, as well as AC/Unity version numbers.

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.