How to enable/disable input using raycast

This is pretty simple…

  1. Get the camera position / actor position
  2. Get the camera orientation, then convert that into a look vector.
  3. Place the look vector at the camera eye position
  4. Scale the look vector by the distance you want to search for objects
  5. Apply a “Line Trace by Channel” node, with the eye position and look vector as end points
  6. Grab the “Hit Actor” from the hit result
  7. 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.
  8. 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.