Toggle Flash Light

One of the key features of my game will be making use of light to survive in the world. There will be times when the flash light on the gun is required, but there will be other times when it will be best to turn it off. Also, at a later stage I intend to introduce a battery concept for the flashlight, and it will be required to turn it off to save battery power.

For now, I just want the ability to turn the flashlight on or off. To do this I am taking advantage of the Toggle Visibility  function in Unreal Blueprints.  My flash light is simply a Spot Light component on my weapon. To be able to toggle the flashlight from the my Character blueprint, I need to create a custom event in my weapon blueprint. This event simply fires Toggle Visibility on the flashlight component.

Toggle Flash light blueprint event

To use this from my character blueprint requires me to call this event on the Weapon component based on some user input. Firstly I need to set up some user input in the project settings from the Edit > Project Settings main menu bar in Unreal Engine. Then select the Input section and add a new Action Mapping. I called the Action Mapping FlashLight, and added the “F” key on the keyboard as a trigger.

Input Setup for Flash Light

Finally, in the Character Blueprint, I had to call my custom event when the input was fired, using the following blueprint:

Fire the Toggle Flash Light Event

All done. Now, whenever the player hits the “F” key on the keyboard, the flash light will toggle on and off. Next step is to add a battery, and that will be the focus of my next post.

Leave a Reply