Invoke Action with button press?

C

CursedToast

Guest
What would be the suggested way of invoking an action with just a button press?
For example, I would like to call MoveItemAction with just pressing a button on a highlighted item on a gamepad.
I don't want these hotkey actions to show up on the item action panel.

Just wanted to check what the suggested method is before I overcomplicate it :)
Thanks!
 
Last edited by a moderator:
You can simply remove the Item Action Panel, Then you can use the action you want by index within the list of actions.

You can choose to use the action on click or through code using any other input.
Since you can add multiple Action Binding (notice that the UI Designer Action Bindings is a list) you can add one with an action panel and one without.

1609322935221.png

In code you would do something like:

Code:
public class ExampleActionBindingInput : MonoBehaviour
{
    [SerializeField] protected ItemViewSlotsContainerItemActionBindingBase m_ActionBinding;

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.A)) {
            
            // Use Trigger Item Action to use the action on the selected slot
            m_ActionBinding.TriggerItemAction();
        }
    }
}

Note that while answering this post I went through the code and found a small bug with the UseItemAction function, this will be fixed in the next update. If you wait for the next update you will be also be able to use a new function : "UseItemActionOnSelectedSlot(int itemActionIndex)"
 
Top