I’m finally trying to incorporate pathfinding into my top down 2D game, and I was hoping to use the recast graph to auto-generate a nav mesh after generating the level.
However, it seems like the recast graph generation does not support 2D colliders, instead relying on 3D terrain/colliders being present.
Is there any particular context on this? I’ve been digging into the code, and it looks like I could add a 2D collider generation step, but I’m also new enough to how this all works that I’m hesitant to start hacking things right away.
Additionally, if I do get 2D collider-based graph generation working… is there a way to propose that change to the core codebase? It seems simple enough and I can’t be the only person working on a 2D game with 2D level geometry
Okay, so I’ve so far gotten basic 2D mesh generation working - basically, I can generate 3D meshes for the 2D colliders in the RecastMeshGatherer (and I added a “generate big 2D plane” phase so there’s no need for an overall plane mesh for the “ground”)
This seems like fairly viable mainline code - I can have this be a local hack for my version, but is there a way to like, upload my changes for consideration?
I’ve managed to get most 2D collider types working very straightforwardly (there’s an issue where it doesn’t “remove” the internal sections of their nav mesh, but A) I’m pretty sure someone more familiar with the asset could manage to fix that, and B) it doesn’t seem to cause any major problems since the different map sections seem actually separate.
The recast graph generation has changed a lot in the beta, but it might be possible to add in your code.
Some changes might be necessary, though. To make sure colliders don’t have holes in them.
Honestly that’s kinda why I was hoping to get these changes pushed - my current project is a bit longer-running and I’d ideally be able to use updated packages without breaking everything
Would you recommend I switch to the beta version?
Also, what do you mean by the colliders not having holes? The way the meshes are generated here is that it basically builds “walls” along the edges of the 2D colliders and expects that to cause cuts into the nav mesh. I think that should properly work with holes? or is there some relevant change in the beta that makes holes more significant?
I got busy with other game stuff and have been working on this again - in anticipation that the answer to this issue might just be “move to the beta” I’ve been trying to port these changes to work in the beta version (which mainly boils down to copying them into the burst recast mesh gatherer).
I’ve gotten it nearly fully working (and it now fixes the holes issue) BUT I’m seeing a weird issue that I don’t understand - meshes are only getting intersected with the graph in the central “square” region?
(Yellow lines are me previewing the full transformed generated mesh data from the 2D colliders)
This seems like it’s almost certainly a bounding box error, but I don’t think it’s on the 2D mesh side and am not sure if there’s some internal thing I need to account for
I was hoping somebody with more knowledge of the plugin’s inner workings could help get this over the finish line I attached a unitypackage with the files I’ve changed (there’s really not that much code) - does anything look wrong?
Basically, since I was computing a fresh bounds anyway I relied on setting the GatheredMesh bounds to new Bounds(), and then downstream logic recomputes it from scratch. This fixed the issue!
Is there any chance this can be incorporated into the beta? I know that’s a lot to ask, but my project really requires using 2D colliders, and relying on the normal package download for the beta means I can’t easily edit things - and I’m hesitant to make such a critical piece of game infrastructure a hacked-in modded thing going forward
Ah sorry - I didn’t set up Git for the project I did this in
The package only contains the 7 files I changed! so if you’re using version control on your end, you should be able to package it in and spot-check any accidental overwrites
I’d really love for this to be added. I have to admit I am a bit disappointed in the lack of current support for graphs with 2D physics (especially large ones). This would help a ton.
Unfortunately I’m getting some errors when I try to import your package.
Import Error Code:(4)
Message: Build asset version error: packages/com.arongranberg.astar/generators/utilities/recastmeshgathererburst.cs in SourceAssetDB has modification time of ‘2023-08-29T10:47:30Z’ while content on disk has modification time of ‘2023-08-11T07:55:39.618Z’
and
The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered:
Packages/com.arongranberg.astar/Generators/Utilities/RecastMeshGatherer.cs
Packages/com.arongranberg.astar/Generators/Utilities/Voxels/VoxelClasses.cs
Packages/com.arongranberg.astar/Editor/GraphEditors/RecastGraphEditor.cs
Packages/com.arongranberg.astar/Generators/RecastGenerator.cs
Packages/com.arongranberg.astar/Generators/Utilities/RecastMeshGathererBurst.cs
I assume it’s because I have A* as a scoped registry, and I’m unable to modify it?
Yep, I don’t think you can edit normal imported packages.
To make these edits, I manually copied the beta package into the project’s Assets directory instead of the readonly package, and the uploaded unitypackage is my edit on those files.
I was hoping to get the changes incorporated into the mainline beta so I can update to the next full version without constantly repeating these hacked-in changes
Copied from packages to a different directory, then removed the package, then copied the files back into the Assets directory.
There were some errors to address but nothing too major - but this was also in a clean project with nothing else in it.
To migrate my project from the previous full release to the hacked beta was a lot more painful, but basically I removed all the old pathfinding code (leaving the project broken) then copied over the hacked beta files into my main project’s Assets/Plugins directory (and then spot checked a bunch of issues).
That all said: If this is adoptable into the mainline beta, I would definitely wait for Aron to incorporate it before tackling these hacks, since you’d need to undo all of this once the beta contains the changes you need.