Hover a button and then press a key for action

I’m trying to make an interaction where I would have several inventory slots and the way to interact with the slots would be: Hover the button and press a key (which will depend on which key for a certain action, for example: Hover + X to inspect, Hover + C to enter placement mode, etc.). Any ideas on how I can have this work?

Cheers

inventory slots and the way to interact with the slots would be: Hover the button

Why are slots buttons?


Sounds like the typical approach should be enough:

  • onMouseEnter / Leave sets a isHovered flag and grants keyboard focus
  • onKeyDown invokes desired action; this could be a simple Switch, a cascading Branch or a tMap look-up

If you want something fancier:

  • have the slot dispatch hover state to the Player Controller
  • Enhanced Input → interface Message the widget → process slot → return some data to the PC

to enter placement mode

One way or another, consider dispatching UI processed data to the player controller and let it handle it. Avoid having slots look thing up in the world.

1 Like

Thank you very much for the answer. :v:

It stops working with the branch cascade for some reason but I assume it’s because the event is “Bubbled”

I use buttons to have hover effects and tool tips more easily.

Why the question? Did you have some advice in mind? :slightly_smiling_face: :thinking:

We’d need to see the script. If you need it looked at, ofc. I’ve been looking at script all day :person_shrugging:

That’d be one of the worst choices for a slot, imho. Avoid native buttons, I say. They’re… inflexible. Normally, you’d make a user widget slot, a simple border is pretty good. OnMouseEnter is your hover, all widgets support tooltips, and handling clicking is trivial by comparison. Native buttons are OK for simple clicks, but they should not do anything else. The way they hungrily consume input will give you a headache as soon as you try make them do anything unbuttonlike.

1 Like

I made it work but I need a tip to make the mouse work too. After all, I’m using it
onKeyDown and it doesn’t accept mouse keys. Do you have any idea how I could implement mouse keys in the graph with the already built cascade of branches? :thinking: :pray:

Interesting :thinking:. I’ll look into it further. I didn’t realize that buttons could consume input in this way, causing headaches in the future. Thanks for the tip! :v:

Wrap the branches in a function or hook them up to an event, call them in onMouseDown and onKeyDown.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.