Below is the blueprint for the “CuttingMesh” This is the dynamic mesh that is being cut.
This mesh has the Collision Type set as Use Complex Collsion as Simple
All of the actual cutting is handled in the ThirdPersonCharacter
blueprint.
Firstly the player character has an invisible dynamic mesh attached to them called DynamicPlane, this is created in the begin play event.
From here the player can manually make the DynamicPlane appear by pressing the q key:
Once the plane is visible, the ThirdPersonCharacter
blueprint then checks for any overlapping ‘CuttingMeshObjects’ and adds them to a local array called ‘CuttingObjects’
From here when the player left clicks the ‘Cut Procedural Mesh’ function is called.
This function starts by going through the ‘Cutting Objects’ array, it then gets the ‘DynamicMeshObject’ Component and sets that as the ‘ExternalDynamicMesh’ variable, I then get the transform for this mesh and make its transform into another variable called ‘Dynamic Mesh Transform’, from here we then get the Dynamic Mesh Component of the ‘External Dynamic Mesh’ variable. After this another new variable called ‘CuttingPlaneTransform’ is created using the ‘DynamicPlane’ transform (reminder: DynamicPlane is the plane the player uses to cut the mesh)-.
We then get the Dynamic Mesh of the ‘Dynamic Plane’ and apply a subtracting mesh boolean between the plane and the dynamic mesh the player wants to cut using ‘Dynamic Mesh Transform’ & ‘Cutting Plane Transform’.
This now creates 2 mesh components which we will get access to in our get mesh by components node.
We then enter a 2 step sequence, on step 0 we add a new ‘Dynamic Mesh Comoponent’ to the Dynamic mesh actor we’re currently working with (this actor is accessed from the for each node.), following this we then get the dynamic mesh and apply another mesh boolean however this time it is an intersection boolean.
After this, we then carry over the collision options from the original External Dynamic Mesh
to the Dynamic Mesh Component we created during this step.
Following this we then combine the newly created dynamic mesh component along with component mesh[1]
Finally in this step we apply both physics and collision to the mesh.
In Step 1, we then apply the same final steps from step 0 (forgive my overuse of the word step) however rather than going to the hassle of adding a new dynamic mesh component we’re simply using the already existing Dynamic Mesh from the actor.
It’s worth noting that these new pieces can’t be cut for some reason, however as far as I can see in the logic of the function the player should be able to cut them as they’re still components of the CuttingMesh Actor.
It’s also worth noting that upon starting the game in editor, physics don’t seem to apply to the CuttingMesh objects (i.e., if they start in the air, they’ll stay there), however they do apply to the newly cut pieces. I tried to go into the construction script of the CuttingMesh and simply apply physics there, however this didn’t change anything.
Upon looking into the physics section of the dynamic mesh component everything seems to be set up correctly
The physics issue is almost definitely related to this warning:
I’ve tried changing the collision type however, when I do this, the ‘CuttingMesh’ no longer collides with the players ‘CuttingPlane’
If you need it, I can provide a link to the github repo where the project is stored.