Unity Input System disabling defaulting value to 0

I’m trying to switch to the new Unity Input System and running into an issue.

I want to set up a simple hotbar system where the event returns a value and that value is used to determine which hotbar button should be highlighted.
I don’t want to set up seperate events for each numerical button from 1 to 0. I would much more prefer to assign value to keybindings and use same event for all of them.

using something like this for it:

public void OnHotbarInteract(InputAction.CallbackContext value)
    {
        int hotbarIndex = Mathf.RoundToInt(value.ReadValue<float>());
        inventory.MakeActive(SlotIndex[hotbarIndex]);
        ChangeHightlight(inventory.ActiveSlot.slotDisplay);
    }

Problem is, the value in this system always defaults to 0, no matter if I’m using axis, or vector or even any value and modify it using keybindings.

This makes sense for continuous input like mouse or player movement but does not really work for other inputs.

No matter if I’m using Clamps or Scaling it, it will always immediately try to return to value 0. I can somewhat control it by using Tap or Press Interactions. But if I hold those buttons they will default to 0 anyways.

So, is there a way to set the value and not update it until next input, esentially disabling defaulting to 0 ?

Or am I approaching this from a wrong angle ?

Heh,

Nevermind I always seem to find an answer after I resign and decide to ask for help :stuck_out_tongue:

For people with similar issue the reason why it defaults to 0 is because action constitutes of 3 stages like in old input system. OnButton, OnButtonDown, OnButtonUp essentially. But now it is event.performed, event.started, event.cancelled.

So in order to fix up my code example all I needed to do is:

if (value.performed)
        {
            int hotbarIndex = Mathf.RoundToInt(value.ReadValue<float>());
            InventoryUI.OnInput(hotbarIndex);
            Debug.Log("HotbarInteract called with value: " + hotbarIndex);
        }

Because on value.cancelled it was defaulting to 0 to notify that I’m concluding my action.