Collisions updating wierdly when updating procedural mesh, dynamic NAV mesh also not updating

Hey all,

for the past week I have been wrapping my head around procedural geometry for deformable terrain that uses a dynamic navmesh.

so far, I am on the 3rd iteration and after scouring every crumb I can find on all these problems via google, answers, forums - I’m bringing it to you guys.

Ok, the specs.
The Procedural is just an Actor with procedural mesh component attached, I have two iterations I will show to you all, both basically do the same thing - althought my (MUCH) larger mesh seems to complete its tasks MUCH faster than the stripped down, more efficient (so it would seem) version… but well get to that later.

here is the construction script for the proc geo actor

quick rundown of what we see here

  1. create index buffer for the sections - as the sections is always a 10x10 grid, I only make this once
  2. use forLoops to make the sector grid, in testing case its only 2x2 - cut off end verts so my main sectors grids are only made inside the 2x2 sector grid
  3. make sectors using the x/y of my previous grid, filling them in 10x10 per sector - feed the sector index and specific sector vert array into a terrain struct array I made
  4. create mesh using a forEach on the terrainData struct with build collision on. takes about 20 seconds. My MUCH longer original setup is about 2x faster, and has a custom create triangles section, but its a mess.

I then have a custom event called terrain Edit, which calls on a macro which is made to be pretty modular as far as adding/subracting/different brushes to affect the mesh, for things like grenade blasts, digging trenches, maybe adding walls you name it. but for now we only have a basic subtract box brush setup.

https://forums.unrealengine.com/attachment.php?attachmentid=95265&d=1464536446

ok so here

  1. set all variables, clear arrays yada yada
  2. find the sections closest to the hit location (for testing purposes its just a mouse hit) - BUG FOUND: I was using 's ‘find closest point in array’ in a 4x forloop to quickly get an array of 4 closest sections, to the hit location so only they will update, on 4.11.2 - I can’t get that particualr set element to actually set, I tried rebuilding it and plenty of other things its definately a bug - so for now I am doing a simple forEach on every vector in the sector grid and comparing them with the location, to find any within a certain distance - this works - but is NOT OPTIMAL. by a long shot.
  3. break open my terrain data, get the exact point inside the ‘blast zone’ with 's ‘is point inside box’- and affect the Z coord on those points, before packing them back up into terrain data just as they were taken out. no mess.
  4. pass the sectors affected to the update mesh for updating.

PROBLEM 1: COLLISION UPDATES ON UPDATE MESH SECTION BP DOES NOT WORK CORRECTLY

In all my tests I cant for the life of me get this to work correctly outside of section 0, it seems almost random in how strange it works. From my research it appears that changing the Vert count you feed into it will force collision not to update, though mine is updating - just VERY strangely. ill show all this in the pics

Game start, nothing much to see here - little character for nav mesh test, 3 spheres for collision testing, navmesh view on

https://forums.unrealengine.com/attachment.php?attachmentid=95266&d=1464536940

Boom! uh oh! wtf is this? Update mesh in all its glory, giving me weird collisions on every sector but 0 (bottom left) - but hey its fast! - note navmesh is not updating either, here i do a little trick with a addactoroffset after the edit to ‘force’ it to rebuild - very messy :(.

https://forums.unrealengine.com/attachment.php?attachmentid=95267&d=1464537100

Now, here is when i Create mesh, giving clean collisions - this is my holy grail, if i can get this with update mesh & not having to ‘trick’ it to rebuild navmesh (dynamic is on and console ‘rebuild navigation’ doesnt work on the procedural terrain changes either)

https://forums.unrealengine.com/attachment.php?attachmentid=95268&d=1464537301

PROBLEM 2: DYNAMIC MESH DOES NOT UPDATE WHEN MESH SECTION IS UPDATED OR RE-CREATED
At the moment, until I can sort the Update Sections, I have been rebuilding the whole mesh - even that will not update - to trick it, I use an AddActorLocalOffset in VERY small values, then revert them straight after. This ofcourse is no solution but it does allow me to see the nav mesh updating.

https://forums.unrealengine.com/attachment.php?attachmentid=95269&d=1464537383

here’s a quick pic with fill polygons turned off for visibility, you can see the holes are there, collision updated (thanks to create mesh) and the spheres have fallen inside. but the navmesh has not changed - this is even after a console ‘rebuild navigation’ command.

So, there’s my problems.

Is there a specific way in which i should feed information to update mesh that im missing?? or is this a bug. I understand the feature is still experimental.

There is a bug with UpdateMeshSection that I’m aware of that might be affecting you. If you have more than one vertex with the same position then it will be cleaned down to one of each position by the PxCooker when you use CreateMeshSection. Then when you call UpdateMeshSection, it tries to do a much faster way of updating the collision by just having PhysX rebuild the BVH. The problem here is you will not end up cleaning the mesh again so it will effectively apply the index buffer to the subset of vertices up to the length it was using… This will hold true if multiple sections within one PMC have vertices with duplicate positions. I’m not sure if the cleaning cycle within the PxCooker can rearrange vertices even if there’s no duplicates yet, as there are some other factors that affect it changing things around.

This results in all sorts of interesting collision problems… I submitted a fix for it a couple weeks ago by just forcing a full recook on Update. I’ll admit it’s not the best solution, but currently it’s the only solution since the PxCooker is hidden under multiple layers of editor cooking related scaffolding. It was closed since it would be slower even though currently it’s fully broken for non-trivial meshes.

I’m not sure about NavMeshes as I’ve never needed them yet.

Thanks for the info, I will keep this in mind moving forward and post any results i get back here - cheers :slight_smile:

Glad I could help! Just wanted to link you this since it might be of use to you. It’s a rewrite of the PMC that solves the collision problems and quite a few other things. Runtime Mesh Component - Marketplace - Unreal Engine Forums