In your input instead of doing when you press and when you release do when you press you call a function that toggles the flashlight…
//In input
InputComponent->BindAction("Flashlight", IE_Pressed, this, &ASleepCharacter::FlashlightToggle);
void ASleepCharacter::FlashlightToggle()
{
IsFlashlightOn = !IsFlashlightOn;
FlashLightComponent->ToggleVisibility("Flashlight");
}
Or something close to that.
That way your not looking at a release event when it doesn’t matter if they release the key or not.