This is pretty simple…
- Get the camera position / actor position
- Get the camera orientation, then convert that into a look vector.
- Place the look vector at the camera eye position
- Scale the look vector by the distance you want to search for objects
- Apply a “Line Trace by Channel” node, with the eye position and look vector as end points
- Grab the “Hit Actor” from the hit result
- Cast the hit actor to the light switch blueprint. If the hit actor is a light switch, the cast will succeed. Then, you can activate a bool flag within the player character which enables the “F” input button.
- When the player activates their input button, you should send a message to the ‘looked at’ actor and tell it to toggle itself. I recommend blueprint interface messages so that you can have multiple switch types. See the content examples for an example of this.