How to scroll between buttons with the scroll wheel?

Hi people.

I created a simple box with 3 buttons (for now), each of these buttons has a weapon assigned to them and when I use it with the mouse it works perfectly. Now all I need to do to perfect this is to make it scrollable through with the mouse scroll (or keys) and make them selectable on a simple mouse click (i’m building a weapon selection bar and i want the user to be able to scroll through the weapons and select the one he uses (similar to half life style only without the submenus). Does anyone know or have some starting point on how to make this work?

  1. Create Input Mapping(s) in your Project Settings for the mouse scrollwheel axis (if it exists - i have never tried it)
  2. Create a WeaponIndex variable (integer) on your player controller or the main widget of your HUD (so it will always exist as long as the player does.
  3. On the player controller class, add input events for the scroll wheel axis, and depending on if it is > 0 or < 0, then increment or decrement the WeaponIndex variable. Use Mod operator on it against the number of weapons in the menu to make the value wrap around if it goes higher than that number or lower than 0.
  4. Either access the widget from the playercontroller and tell it to Set Focus on the child of your vertical box at the index WeaponIndex, or you can get the widget’s Owning Player within the Widget’s code and check what the WeaponIndex is from there, but doing it that way you’ll have to check on tick or a short timer probably.

There is probably a more elegant way to do this but I think it will work.