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
- create index buffer for the sections - as the sections is always a 10x10 grid, I only make this once
- 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
- 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
- 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.
ok so here
- set all variables, clear arrays yada yada
- 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.
- break open my terrain data, get the exact point inside the ‘blast zone’ with’s ‘is point inside box’ (seriously - i <3, you rule dude) - and affect the Z coord on those points, before packing them back up into terrain data just as they were taken out. no mess.
- 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
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 :(.
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)
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.
heres 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, theres my problems.
This game is really riding on the idea of being able to affect the terrain, and possible open up the tools to the player for a map maker also - so I am working on solutions to this non stop, if anyone can help or we can get a thread going to collaborate on a strong BP solution to procedural maps - I am on this project full-time and am willing to work with anyone who wants in on this one so we can all benefit from some awesome run-time bp driven procedural geo. thanks