Forum rules - please read before posting.

Controller button not activating inventory item

edited March 2020 in Technical Q&A

So I have been going at this problem for two days now, seems about time to ask for help cause I am at a loss.

What I want to achieve

I'm working on a side project in which players are hunting for treasures with help of treasure maps they acquire. Although there will be various inventory items I want to seperate these maps from the rest, which is easy because of the inventory categories! Interface wise I want to display a treasuremap UI that displays 1 of the players treasure maps at the time. They can scroll through their treasure maps with the shoulder buttons and activate it with the Y button (if using an Xbox controller).

The problem thusfar

So toying around with the AC Unity UI interface I almost got it working. I can display 1 map at a time and cycle through them with the shoulder buttons. But I can't get the Y button to activate the current displayed item. If I enable mouse input and click on the map this is what should happen:

https://www.dropbox.com/s/gw09kidc69wtn8z/MouseClickWorking.mov?dl=0

Console output for reference:

Interface settings when mouse is enabled:

Current setup for the menu with controller in mind

Right now this is how I have the menu setup in the AC Game Editor menu window. First the treasure map box itself:

Because I can't define an alternative input button in the TreasureMapBox I added a button to the elements and specified the alternative input button:

Just to be sure let's include the interface settings when controller is enabled:

And when I hit play I can still cycle the various items but it just won't activate them:

https://www.dropbox.com/s/gpcymub6cmq0j16/ControllerInputSemiWorking.mov?dl=0

Help

So I am at a loss here. First I thought that maybe the problem was that the button itself was not highlighted/selected even though the scroll buttons seem to work fine without being selected. But if I run an actionlist that highlights the TreasureMapBox/Button (both same component) it still is not working. From here I just went further down the rabbithole and my experiments got more complex with every new idea but all without succes. Right now I am pretty sure the solution is probably very simple and I am just missing something. So AC Forums, please help!

«1

Comments

  • edited March 2020

    Hi Afello, if I understand it correctly the issue is that you can't run the Examine Interaction assigned to the item?

    I don't know how did you handle the UI interface functionality, but if the box has the ID of the current item you can run RunExamineInteraction() method on the item.

    Can you provide more information about how are you sorting these items? Are you scripting it?

    void Update() {
        if(Input.GetKeyDown(KeyCode.Joystick1Button19)) {
            item.RunExamineInteraction();
        }
    }
  • Hi Keks! Thanks for helping :smile:

    Because treasure maps only have one function (being looked at) I made one action list (that spawns the map, handles the animations and switches the camera pov) and assigned it to both the examine and use slot. Problem is that I can't seem to trigger either use or examine with my controller.

    I have no coding skills so I need to handle this stuff with action lists from either AC or Playmaker. Because the scroll item buttons seem to work out of the box I assume this should be able to work as well?

    Inventory setting for the treasure map:

  • edited March 2020

    Well I've never used controller and I'm not using the AC's inventory, so that complicates things :D

    How do you run the examine interaction inside a regular inventory with your controller then? I understand it will execute when you click on the item but how do you select an item and run the interaction within your normal inventory?

  • I have no need of running other inventory interactions because the other inventory items only influence conversations or certain cutscenes. I intend to let situations check if I have a certain item and change the outcome accordingly.

    The standard AC inventory UI works out of the box with a controller if I pause the gameplay and let my cursor cycle through the items. It then uses the Submit input from the Project Settings Input Manager.

  • edited March 2020

    Ok I've found something that could work for you, but I'm able to help you out with a script only I'm afraid. For a different solution someone else will have to answer.

    Inside the runtimeInventory is a method ProcessInventoryBoxClick() which should simulate click on a specific slot in your inventory box.

    If you have only one slot, it should be 0. You would just put in the correct menu name and the inventory box element name. It would go inside the update method under the input condition as in the example I posted above.

    It can simulate left or right click.

    
    KickStarter.runtimeInventory.ProcessInventoryBoxClick(PlayerMenus.GetMenuWithName("menuMame"), (AC.MenuInventoryBox)PlayerMenus.GetElementWithName("menuName", "elementName"), 0, AC.MouseState.Normal);
    
  • Thank you for helping out! Because I have barely any coding skills I am anxious to implement your solution for not really overseeing the consequences. But please do not consider me ungrateful because I am very grateful for you spending time trying to help me!

    If no other solution comes I will surely try editing the script with your solution! Thank you!

  • No worries mate ;)

  • When it comes to scripting, you can also retrieve exactly which item is currently displayed in the inventory box element - and then run its Examine interaction directly.

    Using the same naming convention as above:

    InvItem item = (PlayerMenus.GetElementWithName("menuName", "elementName") as MenuInventoryBox).GetItem (0);
    item.RunExamineInteraction ();
    

    The standard AC inventory UI works out of the box with a controller if I pause the gameplay and let my cursor cycle through the items. It then uses the Submit input from the Project Settings Input Manager.

    So things work when the game is paused? Direct-control over gameplay menus is possible, but has to be enabled specifically with the Engine: Manage systems Action. You may also need to force-select the InventoryBox element manually with the Menu: Select element Action.

  • Problem is that when I use the Menu: Select element action it highlights the box but as soon as I start moving with my character it jumps to one of the scroll buttons. The weird thing is that the scroll inventory buttons don't need to be highlighted to work with the alternative button input.

  • edited March 2020

    How your UI menu is navigated is based on the Navigation setting in your Button components. This can be set to None if you have no need to directly select the scroll buttons.

  • Okay, I'm gonna give it a try! If I don't succeed is it okay if I lay out my plan/wishes for handling inventory UI and maybe you can give me a suggestion for how to set it up without any need for coding if possible? I would be happy to compensate you for the effort :)

  • Give it a go and see - but you've got the code above should it be necessary.

  • Working on it! :) But honestly I wouldn't know what to do with that code, got zero coding skills so changing scripts makes me incredibly nervous. If I don't get it to work I will update this thread but also ask one of my programmer friends to help.

    I still think that the UI setup I want should be able to work without changing scripts. I am not trying to change anything dramatic, just trying to link certain inventory items to specific controller buttons. Also just curious to see what your thoughts or suggestions are.

  • Here is an adaptation of my code above into a custom Action:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionExamineItem : Action
        {
    
            public ActionExamineItem ()
            {
                this.isDisplayed = true;
                category = ActionCategory.Inventory;
                title = "Examine selected";
            }
    
            public override float Run ()
            {
                InvItem item = (PlayerMenus.GetElementWithName("menuName", "elementName") as MenuInventoryBox).GetItem (0);
                if (item != null) item.RunExamineInteraction ();
                return 0f;
            }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                AfterRunningOption ();
            }
    
            #endif
    
        }
    
    }
    

    See the linked tutorial for details on how to install it.

    To run it when an input is pressed, use Active Inputs. Active Inputs are a way to run AC ActionLists when inputs are pressed - see the Manual chapter of the same name.

  • Btw you don't have to be scared of coding. I would recommend learning some minimal basics of coding in Unity. Even though it might seems scary it's actually not something difficult and it will make the whole development easier.

  • Not scared! I would love nothing more than to have the time to learn some basic coding. But between full time game dev job and doing art, game design and music at the side I am so glad there are tools like Adventure Creator and Playmaker that give me the ability to dive into creating my own stuff without coding :) Visual scripting and logic is awesome! But maybe I am overestimating the amount of time it would cost me to learn basic coding for Unity?

  • You should be able to learn it in a few hours.

  • edited March 2020

    A few hours might be a tad optimistic. Like most languages (and I go back to the days of COBOL and FORTRAN and beyond) (and sometimes still think in those languages too, alas) it doesn't take long to learn the syntax, but that's a whole different ball game from learning how to create stable, reliable, optimised, working code using that language

    Still, @Keks is right, it shouldn't take that long to learn basic C# coding for Unity. There are tons of examples and tutorials and whatnot to follow, and you really do get the most out of a system like AC if you have at least some coding ability

  • Aye, what I meant is basics like how to create a new script, where to attach it. Understanding Awake, Start, Update, OnEnable, OnDisable methods. Not really going deep into c# itself just enough to know what's happening and being able to then use scripts being shared here on forum.

    But of course basic knowledge of the actual language could come handy as well.

  • edited March 2020

    Okay... :s

    So I managed to get the action added to the inventory category and got the script to run through the Active Input manager. As I had not yet changed the menu name and the element name in the script I decided to rename the custom action to "ActionExamineTreasureMap", made sure the public class names in the script matched and filled in the corresponding menu name and element name... and then my console started flipping out on errors in scripts I did not even touched. So the ActionList Editor was broken and I couldn't do anything anymore.

    Thankfully I am on git and could move back a commit but what the funk just happened? :o

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.