Issue with Dynamic mesh rendering

Howdy Folks,

Having an issue with my geometry scripting in Unreal 5.0.3

I’ve implemented a mesh cutting system for the player, wherin when they hold the q key a plane appears that can cut a dynamic mesh.

The slicing works for the most part, however an issue arises once the dynamic mesh is cut, whenever the newly cut piece moves it will stop appearing on the screen, however the player is still capable of interacting with the mesh (i.e. jumping on it, running against it).

After stepping out of the editor I’ve confirmed the cut piece still exists even though it doesn’t seem to be rendering.

Is there something I’m doing wrong here or is this expected behavior from a dynamic mesh?

I don’t think it’s inherently expected behavior but it’s hard to really say w/o seeing your blueprints and knowing when they are called. Maybe you can take some other screenshots?

My suggestion for trying to debug would be to take all the dynamics out of it. I see a box appearing to show the cut, is that being appended to the same mesh actor? If so, are you regenerating some things every frame?

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
image

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
image

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.

If an object is using Complex as Simple collision, it can’t be simulated. That’s what the errors are from. In your first image you say you are setting the sphere to have ComplexAsSimple, that is the problem. You need to set it to be Simple and Complex, and then use Set Collision From Mesh to initialize it (eg to a convex hull, or a sphere if the initial shape is always a sphere).

I cannot really follow all the BPs. Here are some things to consider though:

  1. in the first image you have a final ‘ReleaseComputeMesh’ ? this doesn’t make sense as you haven’t created a compute mesh.

  2. You use the cutting plane and then do SplitMeshByComponents, this makes sense to me. Now you (eg when cutting the sphere the first time) have two unique UDynamicMesh objects in the Component Meshes array, which are the two meshes you want. From there it stops making sense. Why are you doing a boolean intersection and union? What I would have expected is that you would set or copy those new meshes into the original / new DMComponents, either via SetDynamicMesh or CopyMeshToMesh.

Note also that in the last BP screenshot the ApplyMeshBoolean node has no input TargetMesh or output TargetMesh, I guess this might just be a no-op then, but it looks like a mistake?

If it were me, I would try to separate out the geometric parts from the spawning-new-Components parts. Verify that the cut geometry is actually what you expect, and then maybe make a Function that spawns and populates a new Component from an input UDynamicMesh, verify that this works independently (eg make sure it works with a debug box or something), and then try putting it all together in a cleaner BP. Just a suggestion though.

The flickering in your original video, where the original sphere is appearing in some frames, to me this suggests that something is continually running. I would try putting some debug-print statements in to make sure that (eg) the cut is only running a single time, the sphere is not being regenerated, etc.

From @rmsEG’s example
So in your BP, UDynamicMeshComponent::NotifyMeshModified() may be required on result mesh comps.