Finding out where the crosshair is pointag at

Heyho guys, I’ve got another question. I have a keypad. Modelled and textured. I imported it in a basic fbx file. So now, I need to know if I enter my Triggerbox of the keypad and I’m pressing E, which key (0,1,2,3,4,5,6,7,8,9,C,<-) the crosshair is pointing on so I can display that on my keypad screen. I’ve read about Line Tracing, but my testing attempts failed. Please help!

First thing I would try is loading up the keypad blueprint and adding a collision box component for each button. Then, set up your character to run a single line trace when pressing “E”. If it hits a collision box… hmm. I would probably do something like

Character Graph:
[Press E Event] – > [Single Line Trace, Returns Collision Box] → [Get Owner?] → Cast to Keypad → [Execute Event - “Button Pressed”, passing in the collision box as the argument]

Keypad Graph:
[Button Pressed] → Maybe feed it into an enum switch containing each collision box for each button, then perform your function here.

I can’t guarantee this will work or that it’s the right way to go about it, but it makes logical sense to me and it would be the first thing I tried.

Edit: After reading Bohrium’s post, I realized I forgot to mention my imagined solution is using an interface. Simple interface with just “Button Pressed” with one input that the keypad uses.

This is how a line trace would work for detecting each of the buttons if you wanted to do all the detecting on the player side. You just replace the Custom Events with whatever you actually want it to do. (However if your character does something other than press buttons on a keypad, it would still check if it’s a button on the keypad at all times so it’s not exactly an ideal solution.)

The slightly more complex way of dealing with it is to use a blueprint interface to send events onto the blueprint of whatever you’re hitting with the trace, so that you can use the same trace for interacting with any number of different things and not just that one keypad. You have to make a new blueprint interface and create a function that takes a “hitresult” input. Then you go to the blueprint props of the Keypad blueprint and add the interface to it. Then you can call the function right after the line trace and send it to over to the actor that you hit and not worry about anything else in your player blueprint. Within the keypad blueprint you can use the “Event HitButtonFunction” and then decide based on the hit result that you packaged together with the event to detect which button you hit and do your further magic there. You do need separate button components for each of the buttons (or an invisible box for each button around the button that blocks the visibility channel if your keypad is just one solid lump of static mesh) so that you can detect which ones you’re actually hitting.

There’s 3 sections in this image, the left is the part in the player blueprint, the middle is the interface and the right one is the keypad blueprint.