In the Content/StarterContent/Props folder, Right-click on the SM_GlassWindow and choose Create Destructible Mesh.
We are going to turn this Static Mesh into a Destructible Mesh which we will break when shot.
Open the Destructible Mesh, then click Fracture Mesh and Save then close the Destructible Mesh Editor window.
Right-click on the SM_GlassWindow_DM asset, and under Asset Actions, select Create Blueprint Using This....
This will prompt you to enter a name and save location for the Blueprint (we used SM_GlassWindow_DM).
Right-click inside the Content Browser, then under Blueprints select Blueprint Interface.
This will again ask you to enter a name and save location for the Blueprint Interface (we used DM_Interface).
Inside the Blueprint Interface, name the existing Function IsDestructible? and add the Inputs shown below by clicking New.
Above we have created three Inputs which we can use to pass variables between Blueprints that implement this Blueprint Interface. We have create two Float variables, one called Damage which will be used to pass an amount of damage to cause to the object we hit and the other Strength the amount of Impulse Strength to apply. Lastly, we added a Vector called HitLoc to hold the location in which the object was hit so that we may pass that information through as well.
Compile and Save then close the Blueprint Interface.
In the Content Browser open the SM_GlassWindow_DM Blueprint, then click the Class Settings option from the tool bar.
In the Details panel, click the Add button under Interfaces and add the DM_Interface.
This will implement the Blueprint Interface in this Blueprint, allowing us to access the functions within it.
Right-click in the graph and search for a ? and select the Event Is Destructible? Event.
Hold Control and drag in the Destructible component from the MyBlueprint window and create the script below.
Here, off the Destructible component we used Apply Damage and connected the damage, strength, location and direction requirements needed to apply damage to our glass window. The actual damage, strength and hit location information will be passed through the Blueprint Interface to this Blueprint from another Blueprint which we will do in a moment.
Compile and Save then close the Blueprint.
In the Content Browser under Content/StarterContent/Blueprints, open the Blueprint_CeilingLight Blueprint.
Using the Blueprint Interface, we will do something different when we shoot this light.
Add the DM_Interface through Class Settings then drag in the PointLight1 component and create the script below.
Here, when Event Is Destructible? is called, we will first set the light to a green color. The second time it is called, we will set the intensity to 0 (turning off the light). Notice that we did not use the Damage, Strength or HitLoc information contained in the interface as it was not relevant to this Blueprint. By using a Blueprint Interface we can make a general function that is called in all Blueprints that implement that interface and function, and then determine what script is executed on each individual Blueprint.
Compile and Save then close the Blueprint.
Inside the Content Browser under Content/FirstPersonBP/Blueprints, open the FirstPersonProjectile Blueprint.
This Blueprint includes the script for the projectile that is spawned in-game when the player fires their weapon.
Add the DM_Interface through Class Settings then Right-click in the graph and add the IsDestructible?(Message) node.
This will execute the function IsDestructible? and all Blueprints that implement the interface and function will also execute.
If you do not see the node, un-check the Context Sensitive option in the upper-right corner of the context menu.
Off the False pin of the Branch connect the IsDestructible? node and connect the Other and HitLocation pins.
Click for full image.
Above, we have added to the existing script that checks if the object that was hit is simulating physics. If it is not simulating physics, we call our IsDestructible? function in our Blueprint Interface and apply 1000 damage and 100 strength to the target (which is gathered from the Event Hit node's Other pin where we also get the Hit Location and assign it to our HitLoc variable to pass through).
Compile and Save, then close the Blueprint.
Drag the SM_GlassWindow_DM and Blueprint_CeilingLight Blueprints into the level then click Play to play in the editor.
Shooting the glass will cause it to fracture and break apart.
Shooting the light once, will cause it to change to the color you specified in step 13.
Shooting the light a second time will cause it to turn off (also specified in step 13).