Rasterize Trees only with Colliders

Hello,

Thanks for this life saving must-have project! I think this is my favourite asset I bought for Unity so far!

My comment or request is about Recast Graph’s tree rasterization.

TL;DR: I would like to have an option in Recast Graph’s Terrain Rasterize Trees for rasterizing only tree colliders (terrain trees without colliders won’t be rasterized with bounds). Getting the Tree Collider should be done (or should have an option for) with GetComponentInChildren instead of just GetComponent.

Long Story:

Unity 2019.3.15f1, URP, AStarPathfinding 4.3.10 Beta
I’m having some trouble lately with scanning a Recast Graph for a forest scene. Previously, I’ve rasterized trees on the terrain and it worked perfectly.

I’ve started to use NatureManufacture tree and bush assets on the terrain. I’m adding bushes as trees onto the terrain to paint them easily (using them as grass-like details don’t work for them). Now, the Recast Graph rasterizes bushes as well and I don’t want bushes to make holes on the graph, I want them to be walkable areas. The bush prefabs don’t have colliders and according to the docs, if the tree(/bush) prefab has no collider it is rasterized using it’s bounds. I’ve found this branch in RecastMeshGatherer.cs and I commented (/disabled) it.

After that, bushes don’t carve holes into the navmesh (as expected), but surprise, trees don’t carve as well. Trees have colliders on them in the prefabs, however as I found out, it’s on one of the child objects of the prefabs (it’s on the first LOD child).

In line 322, I modified GetComponent to GetComponentInChildren and now it works as I want it to work.

Thanks for reading!

Best Regards,
Dávid Szabó

1 Like

Some additional settings for that would be very good indeed, we’ve patched the RecastMeshGatherer.CollectTreeMeshes to only use colliders aswell

I actually did send a patch/feature request to @aron_granberg a while back, he might’ve missed the mail though:

Currently the RecastMeshGatherer only checks if the tree object root has
a collider component and will only use one collider component, even if
there’s multiple.

This combined with the mesh fallback has been causing issues with trees
that use the common unity LODGroup layout (where LOD0 child object has
the collider) and oddly shaped trees with multiple colliders

Any chance you could adjust RecastMeshGatherer.CollectTreeMeshes to
something like
https://gist.github.com/imerr/e95bedb0bed8c3b4e41f311b9f3d6eb1?

Another welcome addition would be another toggle in the UI to set the
tree rasterization to only use colliders instead of falling back to
meshes (that’d get rid of all the custom patching we have to do, since
we don’t want the fallback to meshes for our use case)