How to turn a light on and off

Hi guys, how to make? When a player looks at static mesh he pressed A key and switching lights on/off

Here is way to do it :

-Create a new actor with a light and a mesh (make sure the mesh has collision)

-create an event that toggles light visibility

Inside your character blueprint

When “A” is pressed perform a trace coming from your camera location and going in camera forward vector direction

If the trace hits something , cast the hitted actor to your light bp, if it’s successful call the toggle event from the cast