On this page we will use the OnComponentHit and Event Hit Events to apply damage to and fracture a Destructible Mesh as well as apply an impulse at the hit location to push the destructible, simulating the effects of being hit by a projectile and applying force at the hit location.
For this How To, we are using the Blueprint First Person Template project with Starter Content enabled.
In your project in the Content Browser, go to the Content/Geometry/Meshes folder.
Right-click on 1M_Cube Static Mesh and select Create Destructible Mesh.
We are creating a Destructible Mesh out of this Static Mesh so that when it is shot, we can fracture it causing it to break apart.
Inside the Destructible Mesh Editor, click the Fracture Mesh button then Save and close the window.
Right-click on the newly created Destructible Mesh asset, then under Asset Actions, select Create Blueprint Using This...
Be sure to choose a save location and name for the new Blueprint created.
Inside the Blueprint Editor for the new Blueprint, in the Components window select the Destructible component.
In the Details panel, under Physics, check the Simulate Physics checkbox.
This Blueprint will now simulate physics.
Also in the Details panel, at the bottom under Events, click the OnComponentHit Event.
This will add a new node to and open the Event Graph.
Left-click and drag off the Other Actor pin and search for and add the Cast To FirstPersonProjectile node.
Here we are Casting in Blueprints to another Blueprint called the FirstPersonProjectile Blueprint and making sure that when we hit the Destructible Mesh, that it is infact the FirstPersonProjectile Blueprint that hit it. If it is, then we can apply additional script to fracture the mesh, breaking it apart. If it is not, we will not do anything.
Drag off the Hit pin and add a Break Hit Result node.
The Break Hit Result node gives us access to all sorts of information about the resulting hit and its information.
Drag off the Hit Actor pin from the Break Hit Result and add the Apply Point Damage node.
On the Apply Point Damage node, set the Base Damage to 100 and set the Damage Type Class to Damage Type.
The Apply Point Damage node allows us to not only specifies the amount of damage to cause, but the location at which the damage was inflicted.
On the Apply Point Damage node, connect the remaining wires as shown below.
With all wires connected, your graph should look similar to above.
Compile and Save then, close the Blueprint.
Drag the Blueprint into the level from the Content Browser.
Click Play to play in the editor and use the Left-mouse button to fire a projectile at the cube.
When you play in the editor, you will see that when you hit the cube with the projectile that is fired it causes the cube to take damage and break apart as well as applies an impulse at the location in which it was hit causing it to fly in that direction. The amount of force that is applied is defined inside the FirstPersonProjectile Blueprint which uses the Event Hit node to determine when the projectile actually hits something.
In the Content/FirstPersonBP/Blueprints folder, open the FirstPersonProjectile Blueprint.
Click the image for a larger view.
The script in this Blueprint, checks to see if the object that is hit is simulating physics (which we set to true on our cube Blueprint). If it is, it then applies an Impulse at the location it hits (the amount is defined inside the green box which we have reduced to 50). You can adjust this value to increase/decrease the amount of impulse applied when a hit occurs.