Download

Procedural Mesh does not Update Collision After Modifying Vertices

Hi

I have a UProceduralMeshComponent set up to make an AActor cube out of 8 vertices with collision using


mesh->CreateMeshSection(0, vertices, triangles, TArray<FVector>(), TArray<FVector2D>(), TArray<FColor>(), TArray<FProcMeshTangent>(), true);

Then after construction I call (from a plugin) a method to increase the size of the cube by moving out the vertices a set distance, and then update the mesh with


mesh->UpdateMeshSection(0, vertices, TArray<FVector>(), TArray<FVector2D>(), TArray<FColor>(), TArray<FProcMeshTangent>());

This seems to work fine, the cubes can be added to the editor and grown, but in PIE when I push a physics enabled sphere into the geometry, it can enter the cube until it hits the collision of the older, smaller cube as seen in this video: https://youtu.be/fVYYjyzwFxQ

![currentLow].png|1284x704](upload://zMe84ibI1HIGvjIrQlzMUHK1OM9.png)

I’ve attached delegates to the OnHit&Overlap methods which just provide some debug output visible in the video. The collision settings (in the AActor constructor) of the mesh are kinda messy because I’ve tried so many options to try and get this to work:



RootComponent = mesh;
mesh->OnComponentHit.AddDynamic(this, &AVASFVVolume::OnHit); // delegate, OnComponentHit could be OnComponentOverlap?? Simulate In Editor
mesh->OnComponentBeginOverlap.AddDynamic(this, &AVASFVVolume::OnOverlapBegin);
mesh->OnComponentEndOverlap.AddDynamic(this, &AVASFVVolume::OnOverlapEnd);
mesh->SetNotifyRigidBodyCollision(true);
mesh->bGenerateOverlapEvents = false;
mesh->SetCollisionProfileName(TEXT("BlockAllDynamic")); // https://docs.unrealengine.com/latest/INT/Engine/Physics/Collision/Reference/index.html ??
mesh->bTraceComplexOnMove = true; //https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/bTraceComplexOnMove/index.html // so when moving the object, it uses "complex" collision I think?

I’ve tried calling ClearAllMeshSections() in my ‘update mesh’ method and then CreateMeshSection again, but that seems to have no effect on the problem though.

I’ve tried this in 4.10 and 4.12 and both seem to have the same issue with my code.

Hey @Jayae, wanted to let you know that this is a known issue with the PMC. I’ll recommend switching and using my RuntimeMeshComponent in place of it as it both solves this issue as well as gives many other benefits. You can currently get it from github at the link in my forumn footer, but should also be making its way to the marketplace here soon if you don’t want to compile it yourself. It is 100% free to use, and I believe is going to be replacing the PMC in a future version of the engine. I think currently that bug is kind of being ignored as it’s due to an underlying issue in the engine, which I’ve been talking to James Golding about, and should be fixed here soon.

If you’d rather stick with the PMC, then the only thing I can tell you is to use create in place of update as the problem is due to the way the PMC tries to update collision not working with meshes that have been cleaned by the cooker.

I’ll keep an eye on this thread if you have any other questions related to this. Feel free to contact me in the unreal slackers if you have any questions about either the PMC or RMC.

Hi @Koderz

Thanks for looking at my forum post. I actually found your RuntimeMeshComponent a couple of days ago and have been experimenting with it a little, it seems to fix my problem!
Really, thanks so much for it. I’ll keep an eye on your development of it and good luck on getting it to the marketplace/engine. I’ll get in touch if I have any problems :slight_smile:

Hi @Koderz

I have a follow up question :smiley:

I’m writing an editor plugin which uses the RMC to create volumes and then expand them outwards to collide with level geometry (via vertex manipulation). I’m hoping that in the editor (rather than simulate/PIE) I can change the mesh, and get the new collision information if it overlapped/hit a new worldstatic.

I’ve gotten it to the point where the mesh updates as I expected, (and it looks like your RMC solved the original problem I was having^), however my rmc->OnComponentBeginOverlap() and rmc->OnComponentHit() functions aren’t getting called when volumes have expanded over one another. Calling rmc->GetOverlappingActors() returns an empty TArray as well. Until I start simulate mode and move any of the RMC volumes a tiny amount, then both GetOverlappingActors() and OnComponentBeginOverlap() work fine.

Do you know if there’s a way the overlapping collisions can be checked during editor mode from C++?

@Jayae, while I haven’t attempting anything like that I have a feeling there’s a simple problem here. In the editor I don’t think the full PhysX simulation is running so I doubt those events will ever get fired (same for the GetOverlappingActors()) but I haven’t looked into how they work to know for sure. With that said there’s obviously some, albeit probably limited, collision support in the editor to support things like drop to ground.

Now, in simulation I know of the issue with updating objects collision and it not detecting current collisions as a part of the update until you move it a tiny bit. That’s something I want to look into, even if it’s just doing that automatically within the RMC to get that to work correctly.