Saving Path before Modifiers were applied

Hi there :slight_smile:

Looking for help for a potentially minor problem:
I want to calculate a path with a seeker that uses some modifiers but I want to cache two version of the path: One version without any modifiers and a modified one.

I tried the following by subscribing to the seekers postProcessPath delegate but that path is modified during further calculations and I have no idea how to save the path before postProcessing:

public IEnumerator PathUpdater()
    // just a reference to the path before PostProcessing is applied
    Path beforePostProcessing = null; 

    // Subscribe to the seeker to get the path before it is PostProcessed -> this is basically what I want to save
    seeker.postProcessPath += (p) => beforePostProcessing = p;

    // calculate the path  
    Path path = seeker.StartPath(startPos, targetPos);

    // wait for completing of the path
    yield return path.WaitForPath();

    // check lenght of paths
    // both paths shouldn't be of the same lenght but are in my example as the 'beforePostProcessing' path is processed -> How do I save the beforePostProcessing path?
    Debug.Log("Before Post: " + beforePostProcessing .vectorPath.Count); 
    Debug.Log("Final: " + path.vectorPath.Count);

    // unsubscribe
    seeker.postProcessPath -= (p) => beforePostProcessing = p;

I hope one of you has an idea how I can save the path beforePostProcessing. Another solution would be the use of two different seeker components (one with modifiers attached to the gameObject, one without any modifiers) but this would feel very hacky.


You can get the path before any post-processing using:

path.path.Select(node => (Vector3)node.Position).ToArray();
1 Like

Many thanks. This will help me out a lot! :slight_smile: