FindObjectsByType = evil

Jeez Louise! There’s a few hand grenades we’ve recently found in the source code that definitely needs fixing - things that might be performant for smaller projects, but are causing huge frame drops and performance issues for our large open world.

Firstly, FindObjectsByType. It’s fine(ish) to call this once on initialisation or during Editor time, but there’s noooo way this big boy can play in the league of runtime scripts. In functions such as RecastGenerator.CollectColliderMeshes, when we have the bounds and could easily do a OverlapSphere, we collect every collider in the scene before iterating over all of them! This function = evilness and bad scalability.

Another hand grenade, as well in RecastGeneration. Line 1985 (as a side note, these classes are HUGE. Why???) Regardless of the bounds we supply RecastGenerator.CollectTerrainMeshes, it will go and collect the entire heightmap.

Plz aron. No FindObjectsByType. No huge allocation hand grenades. No classes of thousands and thousands of lines. It’s making working with this very cool, well-featured and well-supported project an absolute nightmare.

Hi

Very true, using OverlapSphere is something that really should be doing.
The recast graph has been mostly written for running in the editor and then caching the result or running at scene start. Updating individual tiles (or even having multiple tiles at all) was added much later and the code has not been updated to optimize for that. At the time when I wrote it, there were no tiles and recast graphs tend to cover the whole world, so using FindObjectsByType was likely better than running lots of OverlapSphere calls.

And I agree, that script should definitely be split into smaller files. I will see what I can do.