GetRemainingPath with limited amount of nodes?

Hi.

I have a particular problem where I’m making a game similar to Rimworld. The agents need to check very often X nodes ahead of their path. Since I’m using path modifiers, the only way I can get the accurate representation of the remaining path is to use GetRemainingPath from AIPath.cs.

However, this returns the ENTIRE path, which is often very huge and not something I need. So I modified the GetRemainingPath method like so:

public void GetRemainingPathLimited(List<Vector3> buffer, int limit)
        {
            buffer.Clear();
            buffer.Add(position);

            if (!interpolator.valid)
            {
                return;
            }

            interpolator.GetRemainingPathLimited(buffer, limit);
        }

public void GetRemainingPathLimited(List<Vector3> buffer, int limit)
            {
                AssertValid();
                buffer.Add(position);

                for (int i = segmentIndex + 1; i < interpolator.path.Count; i++)
                {
                    if (buffer.Count >= limit)
                    {
                        break;
                    }

                    buffer.Add(interpolator.path[i]);
                }
            }

This way, I can quickly get only a specific portion of the remaining path and don’t have to waste a lot of CPU time for nothing.

Would you please consider adding this to A*PP? Perhaps you can make the API a bit nicer or more optimized. It’s a really simple change to implement and it would immensely help my game, and possibly people down the line in the future with a similar problem.

Hi

Is this really a performance critical part? It should be pretty fast, even when getting the whole path.

Hi,

Yes, this is executed (at least) once per frame per agent, and there are a lot of agents. Often, the paths are very long (couple hundred nodes) and I really do not have a need to get the entire path, and clearing and re-adding that many nodes to a list has caused me performance issues.

I’d really appreciate it if you could add this functionality so I don’t have to keep modifying the source code, probably best as an optional parameter that defaults its value to int.MaxValue, so there would be no breaking changes.

Just a quick follow-up, was this perhaps added in the newest beta version of the package since this feature request?