My game currently relies on having hundreds of NPCs to create a dynamic ecosystem, with the only issue I’ve run into with them being the impact on server memory from PathfindingService ComputeAsync. When NPCs are killed or despawned their Path object is cleared with them, yet the Navigation memory on the server never goes down and always slowly climbs as the server runs. Even when servers empty out or all NPCs are destroyed, the memory never goes away.
I’ve tested this on an empty baseplate with a default rig and the pathfinding example provided here (but destroying the Path object after its finished) and I get the same results.
Are the results from ComputerAsync just never cleaned up? Throttling the NPCs ability to use PFS to only every 30 seconds only delays the inevitable, with servers having an extra +500mb of memory after a few hours. Would it be more worth to just have dumber NPCs?
I’m pretty sure the results aren’t cleaned up. Are you making pre determined path’s, so that they get cached or are you creating them each time, that could reduce a bit of memory usage.
I considered this but with players being able to build stuff and things being destructible I felt that the world could change too much for it to really help
I’m going to just go ahead and do a dumber approach to pathfinding for now. Hopefully at some point PFS becomes more performant to use in large amounts, especially for blocky and varying terrain like my game has. If it becomes an issue ill probably generate paths for very specific areas that can be reused, but it does still kinda suck that generated paths linger in memory like this.
I’m going to try making my own table of waypoints just straight from the start to finish position with raycasts to make waypoints around obstacles. I’ve already done a lot to try and make PFS less impactful on the server like my own jump checks and stuff so I’m already barely using it.
I’ve already done walking straight from point A to B without generating a path for optimization sake but having to be stuck with only just that will suck as it made special interactions between NPCs not on just a flat plain easy to do.
I haven’t used PFS much, but I hope all goes well with whether or not your memory issue is fixable. Do you know if switching to a flow field structure would work for your usecase while also performing better? I know you mentioned that you can run hundreds of units fine, but I was wondering how much better PFS is because I’m working on an RTS-like pathfinding system and making a flow field seemed like one of the best options for my static map containing hundreds of units.