First go to the attachments folder and right click the BP_MasterAttachment blueprint and select create child blueprint class and name the new bp class BP_M4A4Flashlight (This is for this tutorial you can name it as you like).
Next open the new blueprint and in the component panel double click the attachment mesh component to get to the viewport of the blueprint. Once there with the attachment component selected you can set the mesh of the attachment in the details panel. Like i have in the image below.
Next with the attachment mesh component still selected in the components panel select add component and search for spot light and add the component. Then rotate it in the direction you need it in as i have in the image below.
With the spot light component select in the details panel untick the visible option and tick the Component replicates option.
Next go to the ItemList data table which is in the items folder. Then create a new row and copy the image below (I have used the flashlight mesh and icon for my example you can use your own mesh and icon as well as name and description)
Next go back to your attachment bp and go to the class defaults and set the settings shown in the image below.
Next if you have not already go to your weapons skeleton and add a new underbarrel socket like shown in the image below. To create the socket select the main bone of your weapon for the M4A4 its the M4A4_Main right click it and select create socket. Make sure when you name it you name it the same as the image Capital letters matter! You can also follow the video below
Once that is done go back to the BP_MasterAttachment blueprint and select the class settings and in the interfaces select add and choose BP_SurvivalInventoryInterface.
Next in your new attachment bp copy the image below
Next in the master range weapon create the nodes shown in the image below
Next go to the BP_M4A4 blueprint and in the class defaults go to the Weapon Settings then to the Attachments and then allowed attachments and click the small + icon and pick the BP_M4A4Flashlight, this allows your new attachment to be attached to the M4A4.
Once this is done you will now be able to attach your flash light attachment to the M4A4 and press F to toggle the light on and off
If something is working correctly check below
If your attachment has the wrong rotation or location on your weapon you can change the socket location and rotation in the weapon skeleton.
If you attachment isn’t attached after attaching it to the weapon in the BP_M4A4Flashlight bp in the class defaults make sure that the attachment socket name is exactly the same name as the socket you created on your weapon skeleton capital letter matter.